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


Java Multipart類代碼示例

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


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

示例1: onlyOneEncodingIsAllowedMultipartFirst

import retrofit2.http.Multipart; //導入依賴的package包/類
@Test public void onlyOneEncodingIsAllowedMultipartFirst() {
  class Example {
    @Multipart //
    @FormUrlEncoded //
    @POST("/") //
    Call<ResponseBody> method() {
      return null;
    }
  }
  try {
    buildRequest(Example.class);
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "Only one encoding annotation is allowed.\n    for method Example.method");
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:RequestBuilderTest.java

示例2: onlyOneEncodingIsAllowedFormEncodingFirst

import retrofit2.http.Multipart; //導入依賴的package包/類
@Test public void onlyOneEncodingIsAllowedFormEncodingFirst() {
  class Example {
    @FormUrlEncoded //
    @Multipart //
    @POST("/") //
    Call<ResponseBody> method() {
      return null;
    }
  }
  try {
    buildRequest(Example.class);
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "Only one encoding annotation is allowed.\n    for method Example.method");
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:RequestBuilderTest.java

示例3: multipartFailsOnNonBodyMethod

import retrofit2.http.Multipart; //導入依賴的package包/類
@Test public void multipartFailsOnNonBodyMethod() {
  class Example {
    @Multipart //
    @GET("/") //
    Call<ResponseBody> method() {
      return null;
    }
  }
  try {
    buildRequest(Example.class);
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "Multipart can only be specified on HTTP methods with request body (e.g., @POST).\n    for method Example.method");
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:RequestBuilderTest.java

示例4: multipartFailsWithNoParts

import retrofit2.http.Multipart; //導入依賴的package包/類
@Test public void multipartFailsWithNoParts() {
  class Example {
    @Multipart //
    @POST("/") //
    Call<ResponseBody> method() {
      return null;
    }
  }
  try {
    buildRequest(Example.class);
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "Multipart method must contain at least one @Part.\n    for method Example.method");
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:RequestBuilderTest.java

示例5: multipartIterableRequiresName

import retrofit2.http.Multipart; //導入依賴的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

示例6: multipartArrayRequiresName

import retrofit2.http.Multipart; //導入依賴的package包/類
@Test public void multipartArrayRequiresName() {
  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

示例7: multipartOkHttpPartForbidsName

import retrofit2.http.Multipart; //導入依賴的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

示例8: multipartIterableOkHttpPart

import retrofit2.http.Multipart; //導入依賴的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

示例9: multipartArrayOkHttpPart

import retrofit2.http.Multipart; //導入依賴的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

示例10: multipartPartMapRejectsOkHttpPartValues

import retrofit2.http.Multipart; //導入依賴的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

示例11: multipartPartMapRejectsNull

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

  try {
    buildRequest(Example.class, new Object[] { null });
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage("Part map was null.");
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:RequestBuilderTest.java

示例12: multipartPartMapRejectsNullValues

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

  Map<String, RequestBody> params = new LinkedHashMap<>();
  params.put("ping", RequestBody.create(null, "pong"));
  params.put("kit", null);

  try {
    buildRequest(Example.class, params);
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage("Part map contained null value for key 'kit'.");
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:21,代碼來源:RequestBuilderTest.java

示例13: multipartPartMapMustBeMap

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

  try {
    buildRequest(Example.class, Collections.emptyList());
    fail();
  } catch (IllegalArgumentException e) {
    assertThat(e).hasMessage(
        "@PartMap parameter type must be Map. (parameter #1)\n    for method Example.method");
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:RequestBuilderTest.java

示例14: multipartNullRemovesPart

import retrofit2.http.Multipart; //導入依賴的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

示例15: multipartPartsShouldBeInOrder

import retrofit2.http.Multipart; //導入依賴的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


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