简体   繁体   English

HttpURLConnection错误-java.io.IOException:服务器返回的HTTP响应代码:URL的400

[英]HttpURLConnection Error - java.io.IOException: Server returned HTTP response code: 400 for URL

I am trying to connect to a URL from a desktop app, and I get the error indicated in the Title of my question 我正在尝试从桌面应用程序连接到URL,但出现问题标题中指出的错误

Url: https://capi-eval.signnow.com/api/user 网址: https//capi-eval.signnow.com/api/user

The Code fragment. 代码片段。

    public void getUrl(String urlString) throws Exception
            {
            String postData=String.format("{{\"first_name\":\"%s\",\"last_name\":\"%s\",\"email\":\"%s\",\"password\":\"%s\"}}", "FIRST", "LAST","test@test.com","USER_1_PASSWORD");
          URL url = new URL (urlString);
          HttpURLConnection connection = (HttpURLConnection)url.openConnection();
          connection.setDoOutput(true);
          connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
          connection.setRequestProperty("Accept", "application/json");
          connection.setRequestProperty("Content-Length",""+postData.length());
          connection.setRequestProperty  ("Authorization", "Basic MGZjY2RiYzczNTgxY2EwZjliZjhjMzc5ZTZhOTY4MTM6MzcxOWExMjRiY2ZjMDNjNTM0ZDRmNWMwNWI1YTE5NmI=");
          connection.setRequestMethod("POST");

          connection.connect();

          byte[] outputBytes =postData.getBytes("UTF-8");

          OutputStream os = connection.getOutputStream();
          os.write(outputBytes);

          os.close();
          InputStream is;
          if (connection.getResponseCode() >= 400) {
              is = connection.getErrorStream();
          } else {
              is = connection.getInputStream();
          }
          BufferedReader in   =
                new BufferedReader (new InputStreamReader (is));
          String line;
          while ((line = in.readLine()) != null) {
                System.out.println (line);
                }
}

public static void main(String[] arg) throws Exception
    {

        System.setProperty("jsse.enableSNIExtension", "false");

        Test s = new Test();
        s.getUrl("https://capi-eval.signnow.com/api/user");
    }

When i dig in the response and print error Stream My output is :: 当我在响应中挖掘并打印错误Stream我的输出是::

{"errors":[{"code":65536,"message":"Invalid payload"}]}

any help appreciated 任何帮助表示赞赏

thanks 谢谢

Maybe something wrong caused by unecoding. 可能是由于未编码引起的问题。 Just have a try by using Base64.encode. 只需尝试使用Base64.encode。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 URLConnection错误 - java.io.IOException:服务器返回HTTP响应代码:URL为400 - URLConnection Error - java.io.IOException: Server returned HTTP response code: 400 for URL 服务器返回 java.io.IOException:服务器返回 HTTP 响应代码:URL 为 400 - server returns java.io.IOException: Server returned HTTP response code: 400 for URL 服务器返回URL的HTTP响应代码:400:java.io.IOException - Server returned HTTP response code: 400 for URL : java.io.IOException java.io.IOException:服务器返回HTTP响应代码:400表示URL - java.io.IOException: Server returned HTTP response code: 400 for URL 获取java.io.IOException:服务器返回的HTTP响应代码:URL为400,但可以在浏览器中正常访问 - Get an java.io.IOException: Server returned HTTP response code: 400 for URL but can access it fine in browser java.io.IOException:服务器为URL返回HTTP响应代码:400 - java.io.IOException: Server returned HTTP response code: 400 for URL: java.io.IOException:服务器返回的HTTP响应代码:URL的400 - java.io.IOException: Server returned HTTP response code: 400 for URL 获取 java.io.IOException:服务器返回 HTTP 响应代码:URL 的 400:使用返回 400 状态代码的 url 时 - Getting java.io.IOException: Server returned HTTP response code: 400 for URL: when using a url which return 400 status code 错误打开连接 java.io.IOException:服务器返回 HTTP 响应代码:URL 501 - Error opening connection java.io.IOException: Server returned HTTP response code: 501 for URL java.io.IOException:服务器返回HTTP响应代码:503的URL:错误 - java.io.IOException: Server returned HTTP response code: 503 for URL: Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM