0

I have a curl request like below

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"}'

I want to convert it to java, so I am doing something like

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*/);

so how can I map above curl request to java?

eatSleepCode
  • 4,427
  • 7
  • 44
  • 93
  • Possible duplicate of [Converting CURL request to HTTP Request Java](http://stackoverflow.com/questions/18636567/converting-curl-request-to-http-request-java) – Erik Jan 03 '17 at 08:09
  • @Erik I think its not completely similar to the one you're saying. I am using `WebResource` here which they don't seem to. We need to use `WebResource` since its used all over the software. – eatSleepCode Jan 03 '17 at 08:14
  • Possible duplicate of [HTTP POST using JSON in Java](http://stackoverflow.com/questions/7181534/http-post-using-json-in-java) – Joe Jan 03 '17 at 08:50

1 Answers1

0

I think you should write something like:

String body = "<JSON here>";

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

as described here.

Maxim
  • 9,701
  • 5
  • 60
  • 108