我如何解决此错误“System.Windows.ni.dll中发生类型'System.Net.WebException'的异常,但未在用户代码中处理” [英] How can i solve this error "An exception of type 'System.Net.WebException' occurred in System.Windows.ni.dll but was not handled in user code"
问题描述
亲爱的先生/女士,
如何解决此错误"System.Windows.ni.dll中出现"System.Net.WebException"类型的异常但未在用户代码中处理"。
How can i solve this error "An exception of type 'System.Net.WebException' occurred in System.Windows.ni.dll but was not handled in user code".
我正在使用此代码。
           
private void btnLogInClick_1(object sender,RoutedEventArgs e)
      {
          if(tbUserName.Text!=""&& tbPassword.Text!="")
          {
              txtUsername = tbUserName.Text.ToString();
              txtPassword = tbPassword.Text.ToString();
              urlString =" http://bluefrogindia.in:8080/GroupCommV1.0 / authenticationLogin?                                 details =" + txtUsername +" $" + txtPassword +" $ bluefrog" ;;
//创建一个新的HttpWebRequest对象。
                    HttpWebRequest request =(HttpWebRequest)WebRequest.Create(urlString);
                      request.ContentType =" application / x-www-form-urlencoded"; $
                      //将Method属性设置为'POST'以将数据发布到URI。
                      request.Method =" POST"; $
                      //开始异步操作
                      request.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback),request);
$
          }¥b $ b          否则
          {
              MessageBox.Show(" not login");
          }
      }
private void btnLogInClick_1(object sender, RoutedEventArgs e)
{
if (tbUserName.Text != "" && tbPassword.Text != "")
{
txtUsername = tbUserName.Text.ToString();
txtPassword = tbPassword.Text.ToString();
urlString = "http://bluefrogindia.in:8080/GroupCommV1.0/authenticationLogin? details="+txtUsername+"$"+txtPassword+"$bluefrog";
// Create a new HttpWebRequest object.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlString);
request.ContentType = "application/x-www-form-urlencoded";
// Set the Method property to 'POST' to post data to the URI.
request.Method = "POST";
// start the asynchronous operation
request.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), request);
}
else
{
MessageBox.Show("not login");
}
}
private static void GetRequestStreamCallback(IAsyncResult asynchronousResult)
      {
          HttpWebRequest request =(HttpWebRequest)asynchronousResult.AsyncState;
          //结束操作
         流postStream = request.EndGetRequestStream(asynchronousResult);
          postStream.Close();
$
          //启动异步操作以获得响应
          request.BeginGetResponse(new AsyncCallback(GetResponseCallback),request);
      }
      private static void GetResponseCallback(IAsyncResult asynchronousResult)
      {
          HttpWebRequest request =(HttpWebRequest)asynchronousResult.AsyncState;
          //结束操作
          HttpWebResponse response =(HttpWebResponse)request.EndGetResponse(asynchronousResult); ----------->我在此行中收到此错误。
          Stream streamResponse = response.GetResponseStream();
          StreamReader streamRead = new StreamReader(streamResponse);
          responseString = streamRead.ReadToEnd();
$
          streamResponse.Close();
          streamRead.Close();
$
          //释放HttpWebResponse
          response.Close();
          if(responseString.StartsWith(" $ 200")))
          {
$
            // NavigationService.Navigate(new Uri(" /Home.xaml",UriKind.Relative));
$
          }¥b $ b          否则
          {
              MessageBox.Show("登录验证失败,您的登录详细信息不正确,请再次检查");
          }
      }
private static void GetRequestStreamCallback(IAsyncResult asynchronousResult)
{
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
// End the operation
Stream postStream = request.EndGetRequestStream(asynchronousResult);
postStream.Close();
// Start the asynchronous operation to get the response
request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
}
private static void GetResponseCallback(IAsyncResult asynchronousResult)
{
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
// End the operation
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult); ----------->I getting this error in this line.
Stream streamResponse = response.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
responseString = streamRead.ReadToEnd();
streamResponse.Close();
streamRead.Close();
// Release the HttpWebResponse
response.Close();
if (responseString.StartsWith("$200"))
{
// NavigationService.Navigate(new Uri("/Home.xaml", UriKind.Relative));
}
else
{
MessageBox.Show("Login Authentication Failed,Your Login details are incorrect,Please Check Once Again");
}
}
注意:-1)我在 收到此错误HttpWebResponse respons(HttpWebResponse)request.EndGetResponse(asynchronousResult); 2)我想从最后一个方法返回值的responseString。
Note :-1) I getting this error at HttpWebResponse respons(HttpWebResponse)request.EndGetResponse(asynchronousResult);2)I want responseString return value from last method.
请解决我的问题或给我相关的代码。我从3天开始绑这个。我不能在这个项目中转发这个问题。请帮助我。
Please solve my problem or give me related code.I am tying this from 3 days . i can't forward step in this project for this problem.Please help me.
谢谢&问候,
SrinivaaS
SrinivaaS
推荐答案
第一步是捕获WebException并告诉我们该例外情况是什么。
First step is for you to trap the WebException and tell us what that exception is.
如果您需要更详细的帮助,或者如果您无法做到这一点,您也可以提供一个简单的问题重现来与Microsoft建立支持案例以获得有关您的帮助电话编码问题。 http://support.microsoft.com/oas
You can also provide a simple repro of the issue if you want more detailed help or if you are unable to do that create a support case with Microsoft for help with your Phone Coding issues. http://support.microsoft.com/oas
这篇关于我如何解决此错误“System.Windows.ni.dll中发生类型'System.Net.WebException'的异常,但未在用户代码中处理”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!