我正在使用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();