我有一段 Java 代码打开一个 HTTP 连接,在上面写入数据,然后检索响应代码。因为,connectin 很好,它应该得到 HTTP_OK(即 200),但它得到 1 作为回报。
这令人困惑,因为 1 在 Http Response 代码规范中没有出现。任何人都可以就潜在的问题领域提出一些想法吗?
以下是一段代码:
URL tempURL = new URL("http://www.google.com");
obj_URLHttpConnectionServlet = (HttpURLConnection)tempURL.openConnection();
obj_URLHttpConnectionServlet.setDoInput(true);
obj_URLHttpConnectionServlet.setDoOutput(true);
OutputStream obj_OutputStream = obj_URLHttpConnectionServlet.getOutputStream();
obj_OutputStream.write(sConfigurationData.getBytes());
obj_OutputStream.flush();
obj_OutputStream.close();
obj_OutputStream = null;
int iResponseCode = obj_URLHttpConnectionServlet.getResponseCode();
System.out.println("Response code received is : " + iResponseCode);
输出
收到的响应代码是:1