如何使用翻新发布(x-www-form-urlencoded)Json数据?

Kam*_*kar 3 android json retrofit2

当我在正文中发布数据时(x-www-form-urlencoded),在Postman中可以正常工作。但是,使用Retrofit 2.0 Android无法正常工作。

@Headers("Content-Type: application/x-www-form-urlencoded")
@POST("/api/jsonws/pushUserData")
Call<ResponseBody>  pushData(@Body JSONObject jsonObj);

JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("role","owner");
            jsonObject.put("id","27001");

        } catch (JSONException e) {
            e.printStackTrace();
        }

        ApiInterface apiInterface1= ApiClient.getClientAuthentication().create(ApiInterface.class);
        Call<ResponseBody> responseBodyCall = apiInterface1.pushData(jsonObject);
Run Code Online (Sandbox Code Playgroud)

这段代码不起作用,我也尝试@FormUrlEncoded。

Nav*_*hna 6

尝试使用@FormUrlEncoded和使用@Field而不是@Body

@FormUrlEncoded
@POST("/api/jsonws/pushUserData")
Call<ResponseBody>  pushData(@Field("role") String role, @Field("id") String id);

ApiInterface apiInterface1= ApiClient.getClientAuthentication().create(ApiInterface.class);
Call<ResponseBody> responseBodyCall = apiInterface1.pushData("owner","27001");
Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

3965 次

最近记录:

7 年,7 月 前