1
這是我必須執行查詢:OkHttp與GSON(POST)問題
http://example.com/webservice/?value=
[{
"table": "images",
"operation": "insert",
"params": [
{
"color_id": 2 ,
"name": "yellow"
}
],
"transactionCompleted": true
}]
但我不能夠做到這一點從Android應用程序。我正在使用OkHttp
和Gson
。看看下面的代碼。當使用調試器時,我發現一切正常,但仍然沒有插入值。任何幫助將不勝感激。
OkHttpClient okHttpClient = new OkHttpClient();
JsonArray form = new JsonArray();
JsonObject item = new JsonObject();
item.addProperty("table", "images");
item.addProperty("operation", "insert");
JsonArray params = new JsonArray();
JsonObject paramItem = new JsonObject();
paramItem.addProperty("color_id", colorId);
paramItem.addProperty("name", name);
params.add(paramItem);
item.add("params", params);
item.addProperty("transactionCompleted", true);
form.add(item);
RequestBody body = RequestBody.create(MIME_JSON, new Gson().toJson(form));
Request request = new Request.Builder()
.addHeader("Accept", "application/json")
.url("http://www.example.com/webservice/?value=")
.post(body)
.build();
okHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
}
@Override
public void onResponse(Response response) throws IOException {
}
});
你能否澄清一下'當我在瀏覽器中輸入它實際上是插入值'?國際海事組織,在瀏覽器中,它的GET請求,而不是POST – BNK
我的錯誤,我不知道 – kinsell
我可以做GET插入?那是錯的嗎? – kinsell