这是我的代码:
String addr = "http://172.26.41.18:8080/domain/list";
URL url = new URL(addr);
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
httpCon.setDoOutput(true);
httpCon.setDoInput(true);
httpCon.setUseCaches(false);
httpCon.setAllowUserInteraction(false);
httpCon.setRequestMethod("GET");
httpCon.addRequestProperty("Authorization", "Basic YWRtaW4fYFgjkl5463");
httpCon.connect();
OutputStreamWriter out = new OutputStreamWriter(httpCon.getOutputStream());
System.out.println(httpCon.getResponseCode());
System.out.println(httpCon.getResponseMessage());
out.close();
我在响应中看到的内容:
500 服务器错误
我打开我的httpCon
变量,看到的是:
POST /rest/platform/domain/list HTTP/1.1
为什么它设置为POST,即使我已经使用httpCon.setRequestMethod("GET");
将其设置为GET?
httpCon.setDoOutput(true);
在我的 Galaxy Nexus 上强制使用 POST,但在运行 Gingerbread 的 Galaxy S2 上没有。 - dzeikei