泽西岛:http错误400

时间:2014-12-19 22:09:14

标签: post curl jersey

我需要在Spring编写一个Jersey客户端。

使用CURL,这有效:

curl --header "Authorization: Basic aaaaaaabbbbb" --header "Content-Type: application/json" --request POST "http://163.162.8.112:9000/path" --data @TestWrapperJob.json
--> return a STRING

-- TestWrapper.json
{ "name": "job2aad",
 "description": "Descrizione test job1",
 "tests": [ {
   "TestPath": "EsempiRiccardo\\TestWrapper",
   "TestDuration": "2"
  } ],
  "topology": null
}

现在我正在尝试在JAVA中翻译,但我得到 HTTP ERROR 400

Client client = Client.create();
String temp = "{ \"name\": \"job2aad\", "
        + " \"description\": \"Descrizione test job1\", "
        + " \"tests\": [ { "
        + "   \"TestPath\": \"EsempiRiccardo\\TestWrapper\", "
        + "   \"TestDuration\": \"2\" "
        + "  } ], "
        + "  \"topology\": null "                   
        + "}";
WebResource webResource = client.resource("http://163.162.8.112:9000/path");
ClientResponse response = webResource.header("Authorization", "Basic aaaaaaabbbbb")
     .type("application/json")
        .post(ClientResponse.class, temp);

怎么了?

Riccardo

1 个答案:

答案 0 :(得分:0)

好的,对不起...... 我找到了答案

  + "   \"TestPath\": \"EsempiRiccardo\\TestWrapper\", "

应该是

  + "   \"TestPath\": \"EsempiRiccardo\\\\TestWrapper\", "