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?

3
  • Possible duplicate of Converting CURL request to HTTP Request Java Commented Jan 3, 2017 at 8: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. Commented Jan 3, 2017 at 8:14
  • Possible duplicate of HTTP POST using JSON in Java Commented Jan 3, 2017 at 8:50

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.