问题
I have a device on Windows Mobile. The device have an access to the internet via WI-FI. I've tried to make a code to get response via Internet with WebHttpRequest and WebHttResponse.
string url = "http://172.20.24.83:80/ProductRESTService.svc/GetProductList/";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "GET";
req.ContentType = "application/xml; charset=utf-8";
req.Timeout = 300000000;
req.Headers.Add("SOAPAction", url);
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
It works fine on Emulator. Unfortunately I have an exception:
Could not establish connection to network on the device only
The device can get an access to the internet via browser, but I can't do it via code.
Do you have any ideas?
回答1:
Although you say you can access the internet, is that the same private internet as the IP 172.20.24.83 is part of a private internet:
Private Internet Addresses:
10.0.0.0/8 IP addresses: 10.0.0.0 -- 10.255.255.255
172.16.0.0/12 IP addresses: 172.16.0.0 -- 172.31.255.255
192.168.0.0/16 IP addresses: 192.168.0.0 – 192.168.255.255
The question is, can your device's browser connect to 172.20.24.83?
I assume your PC is on the 172.16.0.0/12 network too, so the emulator is part of your PC and is also connected to this network. But to which network is your device connected to when using the WiFi connection?
This may be a routing (different subnets) or switch/firewall issue.
Take a look at Start>Settings>Connections>WiFi and select the active WiFi adapter. This will show details about the IP address, subent etc of the WiFi connections. You may also use my NetStatCF to find out the details of the connection.
来源:https://stackoverflow.com/questions/36735967/windows-mobile-internet-on-the-device-via-code