简体   繁体   中英

How to 'convert' a Java REST call to a Postman REST call

I'm having problems doing a Postman REST call copying a REST call in Java.

I tried to set request properties on Postman the same way they're set in Java, but it's not working. I have to send a base64 string with this call (i put in italic the code line where this is done in Java code)

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

I configured Postman like this:

在此处输入图片说明

And i receive this answer:

在此处输入图片说明

EDIT - In few words: the REST call works fine in Java, but i need to do some of these calls in Postman with my own variable (the service i'm calling do some works with base64 string i pass him). EDIT2 - Main problem, in my opinion, is the line:

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

which set the base64 in my Java call, and i don't understand/know how to do the same in my Postman call.

Try only adding the following values:

仅添加这些值

Then, add the content type and the values which you need to pass.

像这样添加内容类型和您需要在此处传递的值

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM