我在Body中使用排序找到了很多POST JSON的解决方案,但我发送的数据不是JsON.
我的数据是:{project_purpose:[EXECUTION]}
从邮递员那里打,我得到的数据但不是在androID中.
请建议我如何做到这一点.
我正在尝试以字符串形式发送,但在错误代码中获得500
我也在JsonObject中发送数据,但没有工作..
这是我要调用的代码..
String bodyST = "{project_purpose: [purpose]}"; OR JsonObject data = new JsonObject(); JsONArray jarray = new JsONArray(); jarray.put("EXECUTION"); data.addProperty("project_purpose",String.valueOf(jarray)); Call<JsonArray> call = APIInterface.getData(mAuthToken,"application/Json",bodyST);解决方法 试试这个
当我尝试以原始形式发布数据时,我遇到了同样的问题,为此,在我获得解决方案后,我浪费了一整天的时间.
>您的API界面应如下所示: –
@POST(Constants.CONTACTS_URL)Call<Object> getUser(@Body Map<String,String> body);
>在你打电话给你的班上
Retrofit retrofit = new Retrofit.Builder() .baseUrl(Constants.BASE_URL) .addConverterFactory(GsonConverterFactory.create()) .build();APIInterface APIInterface = retrofit.create(APIInterface.class);try { Map<String,String> requestbody = new HashMap<>(); requestbody.put("email","[email protected]"); requestbody.put("password","12345678"); Call<Object> call=APIInterface.getUser(requestbody); call.enqueue(new Callback<Object>() { @OverrIDe public voID onResponse(Call<Object> call,Response<Object> response) { try { JsONObject object=new JsONObject(new Gson().toJson(response.body())); Log.e("TAG","onResponse: "+object ); } catch (JsONException e) { e.printstacktrace(); } } @OverrIDe public voID onFailure(Call<Object> call,Throwable t) { } });} catch (Exception e) { e.printstacktrace();}
产量
logcat的:
邮差
注意:-i之后不使用任何模型类来获取数据,检索可以用来存储数据的数据.
总结以上是内存溢出为你收集整理的android – POST原始数据使用Retrofit全部内容,希望文章能够帮你解决android – POST原始数据使用Retrofit所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)