Not able to connect to remote server from WinRT

匿名 (未验证) 提交于 2019-12-03 08:46:08

问题:

I'm making an application which basically just needs to send a piece of XML to a server and return. I'm having trouble however getting this to work and getting very strange errors

public bool Post(string data)     {         string server="http://my-lan-computer:9091/foo"         bool success = false;         HttpClient client = new HttpClient();          try         {             client.PostAsync(server, new StringContent(data, Encoding.UTF8, "text/xml")).Wait(); //error here             success = true;         } catch { }          return success;      } 

The server I'm posting to is not localhost, but it is a computer on my local network. I get this error deeply nested:

innerException: {"An error occurred while sending the request."}  innerException: {"Unable to connect to the remote server"}  innerException: {"An attempt was made to access a socket in a way forbidden by its access permissions 123.123.123.123:9091"} 

I have the internet client capability on my application. I can access my local network and internet by other store applications. I can access the resource in firefox get proper behavior. I don't have a firewall enabled nor an anti-virus that would block these ports

What could possibly cause this obscure error? How can I fix it?

回答1:

To access the LAN, you must declare the Private Network capability in your application manifest. Note that this is different than the Internet capability.



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