Java 如何消除HttpUrlConnection中的响应错误请求400?

Java 如何消除HttpUrlConnection中的响应错误请求400?,java,parse-platform,httpurlconnection,Java,Parse Platform,Httpurlconnection,您好,我正在编写一个Java程序,用于使用parse rest API创建解析对象。 我使用了下面的代码uing HttpUrlConnection,但每次我都收到错误的请求。 我在这里研究了很多线程,但没有得到任何相关的解决方案,所以提出了新的问题 String surl = "https://api.parse.com/1/classes/DrivingTestQuestion"; StringBuilder sb = new StringBuilder(); // 2. O

您好,我正在编写一个Java程序,用于使用parse rest API创建解析对象。 我使用了下面的代码uing HttpUrlConnection,但每次我都收到错误的请求。 我在这里研究了很多线程,但没有得到任何相关的解决方案,所以提出了新的问题

String surl = "https://api.parse.com/1/classes/DrivingTestQuestion";
    StringBuilder sb = new StringBuilder();
    // 2. Open connection
    HttpURLConnection conn =null;
    try {
        URL url = new URL(surl);

        conn = (HttpURLConnection) url.openConnection();

        conn.setRequestMethod("POST");          
        conn.setDoOutput(true);     
        conn.setRequestProperty("X-Parse-Application-Id",
                "87A3v8ImR58torzhrizQwVd6AULIK1dUBxGKqCTf");
        conn.setRequestProperty("X-Parse-REST-API-Key",
                "1tjhBILLSvJE5iEytQ0WvzYf9ig0nQzmuwE2TbXy");
        conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");     
         conn.connect();

        OutputStream os = conn.getOutputStream();
        os.write(json.toString().getBytes("UTF-8"));
         os.close();

        int HttpResult = conn.getResponseCode();
        if (HttpResult == HttpURLConnection.HTTP_OK) {
            BufferedReader br = new BufferedReader(new InputStreamReader(
                    conn.getInputStream(), "utf-8"));
            String line = null;
            while ((line = br.readLine()) != null) {
                sb.append(line + "\n");
            }
            br.close();

            System.out.println("" + sb.toString());

        } else {
            System.out.println(conn.getResponseMessage());
        }
    } catch (MalformedURLException e) {
        e.printStackTrace();
        conn.disconnect();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        conn.disconnect();
    } 
下面是我的json,它是请求主体

{"QuestionNumber":21,"Answers":["Sí, porque es la manera más correcta de reglarlo.","No; debe hacerse con el vehículo inmovilizado en terreno plano yhorizontal.","Sí, siempre que circule lentamente."],"question":"¿Es correcto reglar el espejo retrovisor interior con el vehículo en marcha?","TestNumber":"2","TestTypeId":1}

我尝试使用postman rest客户端并在其中获得响应,但在程序中,getting bad request

Parse不提供Java客户端库吗?不要使用Parse,它们正在关闭。。。我不知道你会从中得到什么样的错误。通常,错误的请求意味着您的请求格式不正确,服务器无法对其进行解析。@RoiKatz我知道parse正在关闭其服务,但目前这是唯一的解决方案requirement@Thilo没有正式的java客户端库,您的确切post请求是什么?(比方说-使用fiddler输出)