Windows Mobile: Internet on the device via code

十年热恋 提交于 2019-12-12 02:08:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!