デスクトップ アプリから URL に接続しようとしていますが、質問のタイトルに示されているエラーが表示されます
URL: https://capi-eval.signnow.com/api/user
コードフラグメント。
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");
}
応答を掘り下げてエラーストリームを出力すると、私の出力は::
{"errors":[{"code":65536,"message":"Invalid payload"}]}
任意の助けをいただければ幸いです
ありがとう