【问题标题】:Converting curl request to Java将 curl 请求转换为 Java
【发布时间】:2017-01-03 08:08:40
【问题描述】:

我有一个如下所示的 curl 请求

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

那么如何将上面的 curl 请求映射到 java?

【问题讨论】:

标签: java curl


【解决方案1】:

我认为你应该写这样的东西:

String body = "<JSON here>";

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

here所述。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-25
    • 2020-12-21
    • 2017-08-03
    • 2018-04-16
    • 2021-02-06
    • 2017-01-13
    • 1970-01-01
    相关资源
    最近更新 更多