【问题标题】:Retrofit POST request Multipart and Field改造 POST 请求 Multipart 和 Field
【发布时间】:2016-11-06 12:06:01
【问题描述】:

> https://api.projectoxford.ai/spid/v1.0/identify?identificationProfileIds={identificationProfileIds}[&shortAudio]

那是我想要到达的终点。

参数标识ProdileIds ===> 字符串

shortAudio ===> 布尔值(可选)

标题

API_Key ===> 字符串

内容类型 ===> 字符串(可选)

请我几乎不知道如何提出请求,但它失败了错误的请求

这是我的接口方法

@Headers("Ocp-Apim-Subscription-Key: 7615c603bcd644cf8a9cd2d8d6cf73c6")
@Multipart
@POST("identify")
Call<ResponseBody> identifySpeaker (@Part MultipartBody.Part file, @Part("identificationProfileId") RequestBody profileIds);

这种类型的输入我稍后在创建实例时传递给它

byte[] audioData = prepareAudioData(mRecordFilePath);
    RequestBody requestFile =    RequestBody.create(MediaType.parse("application/octet-stream"), audioData);
    MultipartBody.Part body = MultipartBody.Part.create(requestFile);

RequestBody profiles = RequestBody.create(MediaType.parse("text/plain"), profiles_list);

adapter.identifyProfile(body,profiles).enqueue   and so on....

在我有这样的 POST 请求之前,我成功地做到了,但那次没有参数 但是这个端点我必须应用参数

这是改造的日志

Logging the response

【问题讨论】:

    标签: java android retrofit retrofit2 microsoft-cognitive


    【解决方案1】:

    我想你想要@Query,而不是@Part

    @Headers("Ocp-Apim-Subscription-Key: ...")
    @Multipart
    @POST("identify")
    Call<ResponseBody> identifySpeaker (
        @Part MultipartBody.Part file,
        @Query("identificationProfileId") RequestBody profileIds,
        @Query("shortAudio") boolean shortAudio)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-24
      • 1970-01-01
      相关资源
      最近更新 更多