我目前正在编写程序与我的网络中的设备进行通信,并且以下代码是我到目前为止,它通过身份验证,并可以从设备获取网页,但我无法获得GET请求来工作,当我运行下面的代码,我得到的错误:使用Get请求与URLConnection
Exception in thread "main" java.io.FileNotFoundException: http://192.168.100.222:80
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
当网页上,其等效要去http://l192.168.xxx.xxx/2?A=3&p=1&X=1234我输入数据,并从tcpflow,它GET /2?A=4&p=1&X=1234 HTTP/1.1
, 我尝试创建一个新的与http://192.168.xxx.xxx/2?A=3&p=1&X=1234的网址连接,它的工作,但我有多个输入选项,我不想为他们每个人创建一个新的连接,我怎么能做同等的保持联系?或者我在代码中做了什么错误?
在此先感谢。
public class main {
public static void main(String[] argv) throws Exception {
Authenticator.setDefault(new MyAuthenticator());
URL url = new URL("http://192.168.xxx.xxx");
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
out.write("Get /2?A=4&p=1&X=1234 HTTP1.1");
out.close();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String decodedString;
while ((decodedString = in.readLine()) != null) {
System.out.println(decodedString);
}
in.close();
}
它没有任何问题对我完美的工作。我尝试与本地主机,而不是在网络。此外,我没有使用'Authenticator' – 2013-03-06 22:31:33
有没有可能的问题,你可以想到? – 3v01 2013-03-07 20:27:34
删除'Authenticator'并检查 – 2013-03-07 20:30:44