gpt4 book ai didi

windows-phone-8 - 如何在 Windows Phone 8 中捕获 Web 异常?

转载 作者:行者123 更新时间:2023-12-04 07:14:39 25 4
gpt4 key购买 nike

我使用 Wamp Server 作为后端,使用 C# 作为前端。出于笑脸的目的,我关闭了服务器。并运行程序。它在输出窗口中抛出以下错误。

'TaskHost.exe' (CLR C:\windows\system32\coreclr.dll: Silverlight AppDomain): Loaded            

'C:\windows\system32\System.Core.ni.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

An exception of type 'System.Net.WebException' occurred in System.Windows.ni.dll and wasn't handled before a managed/native boundary

An exception of type 'System.Net.WebException' occurred in System.Windows.ni.dll and wasn't handled before a managed/native boundary

我的目标是将 Web 异常捕获到消息框中。是否可以。

我已经在使用 try、catch 语句来捕获该异常。但它不起作用。

我的代码
 private void Login_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrWhiteSpace(this.username.Text) || string.IsNullOrWhiteSpace(this.password.Password))
{
MessageBox.Show("Please Enter the Username and Password");
this.username.Text = "";
this.password.Password = "";

}
else
{

string url = ob.localhost + "login_validate.php";
Uri uri = new Uri(url, UriKind.Absolute);

StringBuilder postData = new StringBuilder();
postData.AppendFormat("{0}={1}", "username", HttpUtility.UrlEncode(this.username.Text));// txtUsername.Text));
postData.AppendFormat("&{0}={1}", "password", HttpUtility.UrlEncode(this.password.Password.ToString()));
try
{
WebClient client = default(WebClient);
client = new WebClient();
client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
client.Headers[HttpRequestHeader.ContentLength] = postData.Length.ToString();


client.UploadStringCompleted += client_UploadStringCompleted;
//client.UploadProgressChanged += client_UploadProgressChanged;

client.UploadStringAsync(uri, "POST", postData.ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.Data.ToString());
MessageBox.Show(ex.GetBaseException().ToString());
}

}
prog = new ProgressIndicator();
prog.IsIndeterminate = true;
prog.IsVisible = true;
prog.Text = "Loading....";
SystemTray.SetProgressIndicator(this, prog);


}

请帮我。提前致谢。

最佳答案

尝试使用:

  catch(Webexception ex)
{
Messagebox.Show(ex.innerexception.tostring());
}

关于windows-phone-8 - 如何在 Windows Phone 8 中捕获 Web 异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17788250/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com