你好我在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()
中获取错误请帮助我。