如何将Java REST调用“转换”为Postman REST调用

时间:2019-06-21 10:31:18

标签: java postman

我在执行邮递员REST调用以Java复制REST调用时遇到问题。

我试图在Postman上设置请求属性的方式与在Java中设置属性的方式相同,但无法正常工作。 我必须通过此调用发送一个base64字符串(我在Java代码中用代码行用斜体表示)

 URLConnection connection = new URL(url + content).openConnection();
    connection.setDoOutput(true);
    connection.setUseCaches(false);
    connection.setConnectTimeout(timeout);
    ((HttpURLConnection) connection).setRequestMethod("POST");
    connection.setRequestProperty("Accept", "*/*");
    connection.setRequestProperty("Connection", "keep-alive");
    connection.setRequestProperty("Content-Type", "application/json; charset=utf-8");

    OutputStream output = connection.getOutputStream();

    JSONObject conf = new JSONObject();
    conf.put("signedEvidence", String.format("%s", baos));

    *output.write(conf.toString().getBytes());*
    output.flush();
    checkHttpStatus(connection);

我这样配置邮递员:

enter image description here

我收到这个答案:

enter image description here

编辑-简而言之:REST调用在Java中工作正常,但是我需要使用自己的变量在Postman中进行其中的一些调用(我正在调用的服务对我传递给base64字符串的某些功能也起作用)。 EDIT2-我认为主要问题是该行:

output.write(conf.toString().getBytes());

这在我的Java调用中设置了base64,而我不知道/不知道如何在Postman调用中执行相同的操作。

1 个答案:

答案 0 :(得分:1)

仅尝试添加以下值:

add only these values

然后,添加内容类型和您需要传递的值。

add the content type and the values which you need to pass here like this

相关问题