0

我正在使用WebRequest代码:

bool error = false;
WebException exc = null;
statusText.Text = "Starting";
String urlRequest = "http://****PRIVATER URL****/CC/runCode.php?lang=";
urlRequest += global.language;
urlRequest += "&code=";
urlRequest += Uri.EscapeDataString(global.codeString);
statusText.Text = "Requesting";
webRequest = WebRequest.Create(urlRequest);
webRequest.Proxy = null;
//webRequest.BeginGetResponse(new AsyncCallback(webRequestDone), null);

try
{
    using (resp =  await webRequest.GetResponseAsync())
    {
        //TODO get this working!
    }
}
catch (WebException e)
{
    error = true;
    exc = e;
}
if (error)
{
    await new Windows.UI.Popups.MessageDialog(exc.Message).ShowAsync();
}

无需使用代理即可访问 Web 服务器。如果我在子句之外得到响应try catch,它运行得很好,如下所示:

bool error = false;
                WebException exc = null;
                statusText.Text = "Starting";
                String urlRequest = "http://****PRIVATE URL****/CC/runCode.php?lang=";
                urlRequest += global.language;
                urlRequest += "&code=";
                urlRequest += Uri.EscapeDataString(global.codeString);
                statusText.Text = "Requesting";
                webRequest = WebRequest.Create(urlRequest);
                webRequest.Proxy = null;
                //webRequest.BeginGetResponse(new AsyncCallback(webRequestDone), null);
                resp = await webRequest.GetResponseAsync();
4

1 回答 1

0

看来我想通了。原来我无法访问专用网络。因此,当我在本地网络上时,它总是失败。我必须在 app.appxmanifest 的 Capabilities 下添加它。

于 2013-06-28T20:36:39.437 回答