如何使用Java中的PUT请求编辑属性的原始值?

时间:2016-11-02 10:30:00

标签: java json get put

我可以通过json将属性编辑为KV对。

        HttpPut putRequest = new HttpPut(url);
        putRequest.addHeader("Content-Type", "application/json");
        putRequest.addHeader("Accept", "application/json");

        keyArg.put("key","value");
        StringEntity input;
        try {
            input = new StringEntity(keyArg.toString());
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return "Success";
        }
        putRequest.setEntity(input);

我希望能够在网址上编辑属性的值。 " url?raw" 的GET请求会返回该属性的值。 " url" 的GET请求返回带有键值对的响应

[{"参数1":"值1""参数2":"值2""参数3&# 34;:" value3"," param4":" value4"}]

编辑:我可以通过使用Postman中提供的okhttp代码来实现这一目标

OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = RequestBody.create(mediaType, "1");
Request request = new Request.Builder()
  .url(url+"?raw=")
  .put(body)
  .addHeader("accept", "application/json")
  .addHeader("content-type", "text/plain")
  .addHeader("cache-control", "no-cache")
  .addHeader("postman-token", "aca42ee1-073d-8e3d-cdeb-4e68e8e8b48a")
  .build();

Response response = client.newCall(request).execute();

0 个答案:

没有答案