简体   繁体   English

如何从Windows Phone应用程序发送带有代理地址的HttpWebRequest

[英]How to send a HttpWebRequest with proxy address from Windows phone application

I am developing a Windows phone mobile application. 我正在开发Windows Phone移动应用程序。 I need to send a WebRequest for a specific URL. 我需要发送WebRequest以获取特定的URL。 See below 见下文

HttpWebRequest request = (HttpWebRequest)System.Net.WebRequest.Create(@"http://www.test.html");

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
    if (response.StatusCode == HttpStatusCode.OK)
        return true;//site available
    else
        return false;
}

Obviously, It works well for network without proxy. 显然,它适用于没有代理的网络。 For network using proxy, I need to add the proxy information along with Webrequest. 对于使用代理的网络,我需要将代理信息与Webrequest一起添加。 Since we are doing phone applcaition, We cant hardcode the proxy address in the Webrequest object. 由于我们正在执行电话应用程序,因此我们无法在Webrequest对象中对代理地址进行硬编码。 How to send the Webrequest where the network is using proxy(from Windows phone application) 如何在网络正在使用代理的地方发送Webrequest(来自Windows Phone应用程序)

So far I couldn't find answer for it. 到目前为止,我找不到答案。 However, I have handled the proxy in my desktop application. 但是,我已经在桌面应用程序中处理了代理。 you need to add the following settings in you app.config file. 您需要在app.config文件中添加以下设置。 This settings will add proxy information in all your WebRequest calls. 此设置将在所有WebRequest调用中添加代理信息。 Not sure whether this could help for your mobile app! 不确定这是否对您的移动应用有帮助!

<?xml version="1.0"?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    </startup>
  <!--Provide your Proxy address-->
  <system.net>
    <defaultProxy>
      <proxy
        proxyaddress="[IP Address]:[port]"        
    />
    </defaultProxy>
  </system.net>
</configuration>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM