喜欢php中的body选项在java中使用了什么?

时间:2017-07-26 04:18:50

标签: java php json post put

body选项用于控制封闭请求的实体(例如,PUT,POST,PATCH)的主体。在PHP中它像这样使用

$client->request('POST', '/post', ['body' => $stream]);

但是我想在像http://crawler.ankiti.com这样的java中使用json

{
  "data": [
    {
      "url": "http:\/\/crawler.ankiti.com\/?module=server&do=test",
      "method": "post",
      "options": {
        "body": "post body test 1"
      },
      "target": "wo"
    },
    {
      "url": "http:\/\/crawler.ankiti.com\/?module=server&do=test",
      "method": "post",
      "target": "wo",
      "options": {
        "body": "post body test 1",
        "form_params": {
          "name": "abhay",
          "surname": "aggarwal"
        },
        "headers": {
          "login": "abhay",
          "password": "patparganj405"
        }
      }
    },
    {
      "url": "http:\/\/crawler.ankiti.com\/?module=server&do=test",
      "method": "post",
      "target": "wo",
      "options": {
        "multipart": [
          {
            "name": "file text",
            "path": "\/test\/file.txt"
          },
          {
            "name": "file image",
            "path": "\/test\/file.jpg"
          }
        ]
      }
    }
  ],
  "errors": "",
  "meta": ""
}

我想在一个正文请求中发布一个字符串,该请求存在于此网址的json中。

1 个答案:

答案 0 :(得分:0)

您可以使用httpServlet并按照这样的步骤进行操作。

response.setContentType("application/json");
// Get the printwriter object from response to write the required json object to the output stream      
PrintWriter out = response.getWriter();
// Assuming your json object is **jsonObject**, perform the following, it will return your json object  
out.print(jsonObject);
out.flush();

希望这有帮助