10
我已經使用這種方法https://stackoverflow.com/a/31744565/5829906但不發佈數據。如何使用內容類型爲x-www-form-urlencoded的okhttp庫發佈數據?
這裏是我的代碼
OkHttpClient client = new OkHttpClient();
RequestBody requestBody = new MultipartBuilder()
.type(MultipartBuilder.FORM)
.addFormDataPart("rating", "5").addFormDataPart("comment", "Awesome")
.build();
Request request = new Request.Builder()
.url(url)
.post(requestBody)
.build();
try {
Response response = client.newCall(request).execute();
String responseString = response.body().string();
response.body().close();
}catch (Exception e) {
e.printStackTrace();
}
我試過DefaultHttpClient,這似乎是工作,但它表明棄用,因此想嘗試的東西different..Cant弄清楚什麼是錯的這個