Questions tagged «ion»

4
OkHttp发布正文为JSON
所以,当我使用Koush的离子时,我能够使用一个简单的方法将json正文添加到我的帖子中 .setJsonObjectBody(json).asJsonObject() 我要转到OkHttp,但我确实没有找到一种很好的方法。我到处都是错误400。 谁有想法? 我什至尝试手动将其格式化为json字符串。 String reason = menuItem.getTitle().toString(); JsonObject json = new JsonObject(); json.addProperty("Reason", reason); String url = mBaseUrl + "/" + id + "/report"; Request request = new Request.Builder() .header("X-Client-Type", "Android") .url(url) .post(RequestBody .create(MediaType .parse("application/json"), "{\"Reason\": \"" + reason + "\"}" )) .build(); client.newCall(request).enqueue(new com.squareup.okhttp.Callback() { @Override public …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.