當前位置: 首頁>>代碼示例>>Java>>正文


Java Part類代碼示例

本文整理匯總了Java中retrofit2.http.Part的典型用法代碼示例。如果您正苦於以下問題:Java Part類的具體用法?Java Part怎麽用?Java Part使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Part類屬於retrofit2.http包,在下文中一共展示了Part類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: bodyInNonBodyRequest

import retrofit2.http.Part; //導入依賴的package包/類
@Test public void bodyInNonBodyRequest() {
  class Example {
    @Multipart //
    @PUT("/") //
    Call<ResponseBody> method(@Part("one") String o1, @Body String o2) {
      return null;
    }
  }
  try {
    buildRequest(Example.class);
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "@Body parameters cannot be used with form or multi-part encoding. (parameter #2)\n    for method Example.method");
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:RequestBuilderTest.java

示例2: multipartRequiresName

import retrofit2.http.Part; //導入依賴的package包/類
@Test public void multipartRequiresName() {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part RequestBody part) {
      return null;
    }
  }

  try {
    buildRequest(Example.class, new Object[] { null });
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "@Part annotation must supply a name or use MultipartBody.Part parameter type. (parameter #1)\n"
            + "    for method Example.method");
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:RequestBuilderTest.java

示例3: multipartOkHttpPartForbidsName

import retrofit2.http.Part; //導入依賴的package包/類
@Test public void multipartOkHttpPartForbidsName() {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part("name") MultipartBody.Part part) {
      return null;
    }
  }

  try {
    buildRequest(Example.class, new Object[] { null });
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "@Part parameters using the MultipartBody.Part must not include a part name in the annotation. (parameter #1)\n"
            + "    for method Example.method");
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:RequestBuilderTest.java

示例4: multipartArrayOkHttpPart

import retrofit2.http.Part; //導入依賴的package包/類
@Test public void multipartArrayOkHttpPart() {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part("ping") MultipartBody.Part[] part) {
      return null;
    }
  }

  try {
    buildRequest(Example.class, new Object[] { null });
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "@Part parameters using the MultipartBody.Part must not include a part name in the annotation. (parameter #1)\n"
            + "    for method Example.method");
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:RequestBuilderTest.java

示例5: multipartPartMapRejectsOkHttpPartValues

import retrofit2.http.Part; //導入依賴的package包/類
@Test public void multipartPartMapRejectsOkHttpPartValues() {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@PartMap Map<String, MultipartBody.Part> parts) {
      return null;
    }
  }

  try {
    buildRequest(Example.class, new Object[] { null });
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "@PartMap values cannot be MultipartBody.Part. Use @Part List<Part> or a different value type instead. (parameter #1)\n"
            + "    for method Example.method");
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:RequestBuilderTest.java

示例6: multipartIterableRequiresName

import retrofit2.http.Part; //導入依賴的package包/類
@Test public void multipartIterableRequiresName() {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part List<RequestBody> part) {
      return null;
    }
  }

  try {
    buildRequest(Example.class, new Object[] { null });
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "@Part annotation must supply a name or use MultipartBody.Part parameter type. (parameter #1)\n"
            + "    for method Example.method");
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:RequestBuilderTest.java

示例7: multipartIterableOkHttpPart

import retrofit2.http.Part; //導入依賴的package包/類
@Test public void multipartIterableOkHttpPart() {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part("ping") List<MultipartBody.Part> part) {
      return null;
    }
  }

  try {
    buildRequest(Example.class, new Object[] { null });
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "@Part parameters using the MultipartBody.Part must not include a part name in the annotation. (parameter #1)\n"
            + "    for method Example.method");
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:RequestBuilderTest.java

示例8: multipartNullRemovesPart

import retrofit2.http.Part; //導入依賴的package包/類
@Test public void multipartNullRemovesPart() throws IOException {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part("ping") String ping, @Part("fizz") String fizz) {
      return null;
    }
  }
  Request request = buildRequest(Example.class, "pong", null);
  assertThat(request.method()).isEqualTo("POST");
  assertThat(request.headers().size()).isZero();
  assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");

  RequestBody body = request.body();
  Buffer buffer = new Buffer();
  body.writeTo(buffer);
  String bodyString = buffer.readUtf8();

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"ping\"")
      .contains("\r\npong\r\n--");
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:24,代碼來源:RequestBuilderTest.java

示例9: multipartPartsShouldBeInOrder

import retrofit2.http.Part; //導入依賴的package包/類
@Test public void multipartPartsShouldBeInOrder() throws IOException {
  class Example {
    @Multipart
    @POST("/foo")
    Call<ResponseBody> get(@Part("first") String data, @Part("second") String dataTwo, @Part("third") String dataThree) {
      return null;
    }
  }
  Request request = buildRequest(Example.class, "firstParam", "secondParam", "thirdParam");
  MultipartBody body = (MultipartBody) request.body();

  Buffer buffer = new Buffer();
  body.writeTo(buffer);
  String readBody = buffer.readUtf8();

  assertThat(readBody.indexOf("firstParam")).isLessThan(readBody.indexOf("secondParam"));
  assertThat(readBody.indexOf("secondParam")).isLessThan(readBody.indexOf("thirdParam"));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:RequestBuilderTest.java

示例10: implicitMultipartForbidden

import retrofit2.http.Part; //導入依賴的package包/類
@Test public void implicitMultipartForbidden() {
  class Example {
    @POST("/") //
    Call<ResponseBody> method(@Part("a") int a) {
      return null;
    }
  }
  try {
    buildRequest(Example.class);
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "@Part parameters can only be used with multipart encoding. (parameter #1)\n    for method Example.method");
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:16,代碼來源:RequestBuilderTest.java

示例11: simpleMultipart

import retrofit2.http.Part; //導入依賴的package包/類
@Test public void simpleMultipart() throws IOException {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part("ping") String ping, @Part("kit") RequestBody kit) {
      return null;
    }
  }

  Request request = buildRequest(Example.class, "pong", RequestBody.create(
      MediaType.parse("text/plain"), "kat"));
  assertThat(request.method()).isEqualTo("POST");
  assertThat(request.headers().size()).isZero();
  assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");

  RequestBody body = request.body();
  Buffer buffer = new Buffer();
  body.writeTo(buffer);
  String bodyString = buffer.readUtf8();

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"ping\"\r\n")
      .contains("\r\npong\r\n--");

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"kit\"")
      .contains("\r\nkat\r\n--");
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:31,代碼來源:RequestBuilderTest.java

示例12: multipartArray

import retrofit2.http.Part; //導入依賴的package包/類
@Test public void multipartArray() throws IOException {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part("ping") String[] ping) {
      return null;
    }
  }

  Request request =
      buildRequest(Example.class, new Object[] { new String[] { "pong1", "pong2" } });
  assertThat(request.method()).isEqualTo("POST");
  assertThat(request.headers().size()).isZero();
  assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");

  RequestBody body = request.body();
  Buffer buffer = new Buffer();
  body.writeTo(buffer);
  String bodyString = buffer.readUtf8();

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"ping\"\r\n")
      .contains("\r\npong1\r\n--");

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"ping\"")
      .contains("\r\npong2\r\n--");
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:31,代碼來源:RequestBuilderTest.java

示例13: multipartOkHttpIterablePart

import retrofit2.http.Part; //導入依賴的package包/類
@Test public void multipartOkHttpIterablePart() throws IOException {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part List<MultipartBody.Part> part) {
      return null;
    }
  }

  MultipartBody.Part part1 = MultipartBody.Part.createFormData("foo", "bar");
  MultipartBody.Part part2 = MultipartBody.Part.createFormData("kit", "kat");
  Request request = buildRequest(Example.class, Arrays.asList(part1, part2));
  assertThat(request.method()).isEqualTo("POST");
  assertThat(request.headers().size()).isZero();
  assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");

  RequestBody body = request.body();
  Buffer buffer = new Buffer();
  body.writeTo(buffer);
  String bodyString = buffer.readUtf8();

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"foo\"\r\n")
      .contains("\r\nbar\r\n--");

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"kit\"\r\n")
      .contains("\r\nkat\r\n--");
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:32,代碼來源:RequestBuilderTest.java

示例14: multipartOkHttpArrayPart

import retrofit2.http.Part; //導入依賴的package包/類
@Test public void multipartOkHttpArrayPart() throws IOException {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part MultipartBody.Part[] part) {
      return null;
    }
  }

  MultipartBody.Part part1 = MultipartBody.Part.createFormData("foo", "bar");
  MultipartBody.Part part2 = MultipartBody.Part.createFormData("kit", "kat");
  Request request =
      buildRequest(Example.class, new Object[] { new MultipartBody.Part[] { part1, part2 } });
  assertThat(request.method()).isEqualTo("POST");
  assertThat(request.headers().size()).isZero();
  assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");

  RequestBody body = request.body();
  Buffer buffer = new Buffer();
  body.writeTo(buffer);
  String bodyString = buffer.readUtf8();

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"foo\"\r\n")
      .contains("\r\nbar\r\n--");

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"kit\"\r\n")
      .contains("\r\nkat\r\n--");
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:33,代碼來源:RequestBuilderTest.java

示例15: multipartIterable

import retrofit2.http.Part; //導入依賴的package包/類
@Test public void multipartIterable() throws IOException {
  class Example {
    @Multipart //
    @POST("/foo/bar/") //
    Call<ResponseBody> method(@Part("ping") List<String> ping) {
      return null;
    }
  }

  Request request = buildRequest(Example.class, Arrays.asList("pong1", "pong2"));
  assertThat(request.method()).isEqualTo("POST");
  assertThat(request.headers().size()).isZero();
  assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");

  RequestBody body = request.body();
  Buffer buffer = new Buffer();
  body.writeTo(buffer);
  String bodyString = buffer.readUtf8();

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"ping\"\r\n")
      .contains("\r\npong1\r\n--");

  assertThat(bodyString)
      .contains("Content-Disposition: form-data;")
      .contains("name=\"ping\"")
      .contains("\r\npong2\r\n--");
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:30,代碼來源:RequestBuilderTest.java


注:本文中的retrofit2.http.Part類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。