2017-01-03 90 views
0

我有一个像下面转换卷曲请求的Java

curl --header "Content-Type: application/json" -X POST http://192.168.10.33:2003/jobs --data '{"path": "./examples/target/scala-2.10/mist_examples_2.10-0.0.2.jar", "className": "SimpleContext$", "parameters": {"digits": [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]}, "externalId": "12345678", "namespace": "foo"}' 

我想将它转换成Java卷曲的要求,所以我做这样

Client client= Client.create(); 
WebResource resource = client.resource("http://192.168.10.33:2003/jobs"); 
String response = resource.type(MediaType.APPLICATION_JSON_TYPE).post(/*not sure what to do here*/); 

这样的东西我怎么能映射上述卷曲请求到Java?

+0

[将CURL请求转换为HTTP请求Java]可能重复(http://stackoverflow.com/questions/18636567/converting-curl-request-to-http-request-java) – Erik

+0

@Erik我认为它不完全类似于你所说的那个。我在这里使用'WebResource',他们似乎没有。我们需要使用'WebResource',因为它已经在整个软件中使用了。 – eatSleepCode

+0

[Java中使用JSON的HTTP POST的可能重复](http://stackoverflow.com/questions/7181534/http-post-using-json-in-java) – Joe

回答

0

我想你应该写这样的:所描述here

String body = "<JSON here>"; 

String response = resource. 
    type(MediaType.APPLICATION_JSON_TYPE). 
    post(String.class, body);