如何解决webclient请求期间发生的异常。 [英] How to solve an exception occurred during a webclient request.

查看:4075
本文介绍了如何解决webclient请求期间发生的异常。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

System.dll中出现'System.Net.WebException'类型的异常,但未在用户代码中处理



附加信息:a期间发生异常WebClient请求。



我尝试过:



公共字符串sendSMS ()

{

string titile = ddlTitle.SelectedItem.Text;

txtmsg.Text =Welcome+ titile ++ txtName .Text +to Wellness Solutions Pvt Ltd!。\ n您的患者ID是:+ PatientID.Text +。\ n登录详情:\ n分支:+ branch_name +\ n用户名:+ PatientID.Text +\ n密码:+ password.ToString()+;

String message = HttpUtility.UrlEncode(txtmsg.Text);

using (var wb = new WebClient())

{

byte [] response = wb.UploadValues(https://api.textlocal.in/send/, new NameValueCollection()

{

{username,shinju@exmech.com},

{hash,2d4666b1584a17da83c44673218b2229c9f7bcdb},

{ numbers,txtMobile.Text},

{message,message},

{sender,TXTLCL},

});

string result = System.Text.Encoding.UTF8.GetString(response);

返回结果;

}

}

An exception of type 'System.Net.WebException' occurred in System.dll but was not handled in user code

Additional information: An exception occurred during a WebClient request.

What I have tried:

public string sendSMS()
{
string titile = ddlTitle.SelectedItem.Text;
txtmsg.Text = "Welcome " + titile + " " + txtName.Text + " to Wellness Solutions Pvt Ltd !. \n Your Patient ID is: " + PatientID.Text + ".\n Login Details:\n Branch: " + branch_name + "\n username: " + PatientID.Text + "\n password :" + password.ToString() + "";
String message = HttpUtility.UrlEncode(txtmsg.Text);
using (var wb = new WebClient())
{
byte[] response = wb.UploadValues("https://api.textlocal.in/send/", new NameValueCollection()
{
{"username" , "shinju@exmech.com"},
{"hash" , "2d4666b1584a17da83c44673218b2229c9f7bcdb"},
{"numbers" , txtMobile.Text},
{"message" , message},
{"sender" , "TXTLCL"},
});
string result = System.Text.Encoding.UTF8.GetString(response);
return result;
}
}

推荐答案

首先做两件事:

1)添加试试。 ..catch 阻止,以便您可以检查异常细节。

2)使用调试器登录异常对象(如果需要,它是InnerException)并准确找出什么例外被捕获,以及在哪里。



我们无法为您做任何事情:我们无法运行您的代码并获得完全相同的结果因为我们不喜欢吨有访问您的数据。所以取决于你:使用调试器并开始查看正在发生的事情!
Start by doing two things:
1) Add a try...catch block so that you can examine the exception detail.
2) Use the debugger to log at the exception object (and it's InnerException if necessary) and find out exactly what exception is being caught, and where.

We can't do any of that for you: we can't run your code and get exactly the same result you do because we don't have access to your data. So it's up to you: use the debugger and start looking at what is happening!


这篇关于如何解决webclient请求期间发生的异常。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆