IOException:服务器返回HTTP响应代码:Java 1.6中的URL为400,但在1.7& 1.8

时间:2017-06-08 17:58:51

标签: java httpurlconnection

你好我在1.6的http响应中得到400,但在1.7和1.8

中工作正常 有些人可以帮助我。

代码:

System.setProperty("https.protocols","TLSv1,SSLv2Hello");   
String  urlParameters  = Constants.GRANT_TYPE+"&"+Constants.CLIENT_ID+"&"+Constants.CLIENT_SECRET+"&"+Constants.USER_NAME+"&"+Constants.PASSWORD;

        URL url;

        HttpURLConnection con = null;  
        try {
          //Create connection
            url = new URL(Constants.AUTH_URL);
        String s =  URLEncoder.encode(Constants.AUTH_URL);
          con = (HttpURLConnection)url.openConnection();
          con.setRequestMethod("POST");
            con.setRequestProperty("User-Agent", "Mozilla/5.0");
            con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
            con.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded"); 
              con.setRequestProperty( "charset", "utf-8");

            // Send post request
            con.setDoOutput(true);
            DataOutputStream wr = new DataOutputStream(con.getOutputStream());
            wr.writeBytes(urlParameters2);
            wr.flush();
            wr.close();
int responseCode = con.getResponseCode();
            System.out.println(responseCode);
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(con.getInputStream()));
            String inputLine;
            StringBuffer response = new StringBuffer();

            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }
            in.close();

在con.getInputStream()

中获取错误

请帮助我。

0 个答案:

没有答案