我正在使用“https”从服务器调用 web 服务,我使用了简单的 HttpURLConnection 代码而不是 HttpsURLConnection,代码在平板电脑(OS 4.0.4)上运行 f9,但在我的设备(2.3.5)上却不行。
代码很简单:
URLConnection urlConn = null;
URL url = new URL("https://myurl");
urlConn = null;
urlConn = url.openConnection();
if (!(urlConn instanceof HttpURLConnection)) {
try {
throw new IOException("URL is not an Http URL");
} catch (IOException e) {
e.printStackTrace();
}
}
HttpURLConnection httpConn = (HttpURLConnection) urlConn;
httpConn.setAllowUserInteraction(false);
httpConn.setInstanceFollowRedirects(true);
try {
httpConn.setRequestMethod("GET");
httpConn.connect();
} catch (ProtocolException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
httpResponsecode = httpConn.getResponseCode();
如果我在设备上调用,httpresponsecode 为 400,但从平板电脑调用时为 200。
有什么建议么?