我想JSON數據發送到服務器這是在形式如何使用改進將json數據發送到服務器?
{
"comments": "Testing",
"quantity": 0,
"retailerId": 0,
"retailerquote": 0,
"subProductId": 999,
"unit": "kg",
"wholesalerid": 999
}
,當它真正得到貼吧將返回「補充說:」作爲迴應,我不知道什麼是錯的代碼,它顯示我「方法不允許」。 這就是我如何做到的。
HashMap<String,String> header = new HashMap<String, String>();
header.put("Content-type","application/json");
HashMap<String,String> data = new HashMap<String, String>();
data.put("comments",comments);
data.put("quantity",quantity);
data.put("retailerId",retailerID);
data.put("retailerquote",retailerQuote);
data.put("wholesalerId",wholesalerID);
data.put("unit",unit);
data.put("subProductId",subProductID);
Call<RequestQuoteCheck> call = RetrofitBaseAdapter.getCommonPathInterfaceRequestQuote().requestQuoteCheck(data);
call.enqueue(new retrofit2.Callback<RequestQuoteCheck>() {
@Override
public void onResponse(Call<RequestQuoteCheck> call, Response<RequestQuoteCheck> response) {
Toast.makeText(getApplicationContext(),response.message(),Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(Call<RequestQuoteCheck> call, Throwable t) {
}
});
這是基本適配器類
public static WebserviceMethods getCommonPathInterfaceRequestQuote() {
final OkHttpClient okHttpClient = new OkHttpClient.Builder()
.readTimeout(30, TimeUnit.SECONDS)
.connectTimeout(30, TimeUnit.SECONDS)
.build();
Retrofit restAdapterRequestQuote = new Retrofit.Builder()
.baseUrl(Constants.baseURLforRequestQuote)
.addConverterFactory(GsonConverterFactory.create())
.client(okHttpClient)
.build();
WebserviceMethods retrofitinterfaces = restAdapterRequestQuote.create(WebserviceMethods.class);
return retrofitinterfaces;
}
}
,這是webServiceMethods.java文件
@POST("requestQuoteCheck")
Call<RequestQuoteCheck> requestQuoteCheck(
@HeaderMap Map<String,String> data);
您可以更改申請的方法'''GET'''。 – KeLiuyue