Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# HttpWebRequest BeginGetResponse Windows Phone中的参数异常_C#_.net_Windows Phone 7_Parameters_Httpwebrequest - Fatal编程技术网

C# HttpWebRequest BeginGetResponse Windows Phone中的参数异常

C# HttpWebRequest BeginGetResponse Windows Phone中的参数异常,c#,.net,windows-phone-7,parameters,httpwebrequest,C#,.net,Windows Phone 7,Parameters,Httpwebrequest,我将我的应用程序发布请求发送到某个URL。当我第一次发送它时,它是正常的,但是当我再次调用方法SendBookingFreeCapacity(),我得到 函数“私有无效应用程序未处理的异常(对象发送方,ApplicationUnhandledExceptionEventArgs)”中App.xaml中的ApplicationUnhandledExceptionEventArgs 问题是线路: webRequest.BeginGetResponse(new AsyncCallback(GetBoo

我将我的应用程序发布请求发送到某个URL。当我第一次发送它时,它是正常的,但是当我再次调用方法
SendBookingFreeCapacity()
,我得到

函数“私有无效应用程序未处理的异常(对象发送方,ApplicationUnhandledExceptionEventArgs)”
中App.xaml中的
ApplicationUnhandledExceptionEventArgs

问题是线路:

webRequest.BeginGetResponse(new AsyncCallback(GetBookingFreeCapacitydResponseCallback), webRequest);
这是我的密码:

public static void SendBookingFreeCapacity() {
    var url = "https://..../getFreeCapacity";

    HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
    webRequest.Method = "POST";
    webRequest.ContentType = "application/x-www-form-urlencoded";

    webRequest.BeginGetRequestStream(
        new AsyncCallback(GetBookingFreeCapacityRequestStreamCallback), 
        webRequest);
}

private static void GetBookingFreeCapacityRequestStreamCallback(
    IAsyncResult asynchronousResult)
{
    try {
        HttpWebRequest webRequest = 
            (HttpWebRequest)asynchronousResult.AsyncState;

        string postData = string.Empty;

        System.IO.Stream postStream = 
            webRequest.EndGetRequestStream(asynchronousResult);

        postData = "<?xml version=\"1.0\"?>" 
                   + "<request>" 
                   + "<login>" + Globals.Login + "</login>" 
                   + "<password>" + Globals.Password + "</password>" 
                   + "<hotId>" + htl.hotId + "</hotId>" 
                   + "<term>" 
                   + "<from>" + dayParser(Globals.PrijezdDate) + "</from>" 
                   + "<to>" + dayParser(Globals.OdjezdDate) + "</to>" 
                   + "</term>" 
                   + "</request>";

        byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(postData);

        postStream.Write(byteArray, 0, byteArray.Length);
        postStream.Close();

        webRequest.BeginGetResponse(
            new AsyncCallback(GetBookingFreeCapacitydResponseCallback),
             webRequest); //after this I get the exception
    }
    catch (Exception ex) { }
}

private static void GetBookingFreeCapacitydResponseCallback(
    IAsyncResult asynchronousResult)
{
    try {
        HttpWebRequest webRequest =
            (HttpWebRequest)asynchronousResult.AsyncState;
        //some code...
    }
    catch (Exception ex) { }
}
public static void SendBookingFreeCapacity(){
变量url=”https://..../getFreeCapacity";
HttpWebRequest webRequest=(HttpWebRequest)webRequest.Create(url);
webRequest.Method=“POST”;
webRequest.ContentType=“application/x-www-form-urlencoded”;
webRequest.BeginGetRequestStream(
新的异步回调(GetBookingFreeCapacityRequestStreamCallback),
网络请求);
}
私有静态void GetBookingFreeCapacityRequestStreamCallback(
IAsyncResult(异步结果)
{
试一试{
HttpWebRequest webRequest=
(HttpWebRequest)asynchronousResult.AsynchState;
string postData=string.Empty;
System.IO.Stream postStream=
EndGetRequestStream(异步结果);
postData=“”
+ "" 
+“”+Globals.Login+“”
+“”+全局密码+“”
+“”+htl.hotId+“”
+ "" 
+“+dayParser(Globals.PrijezdDate)+”
+“+dayParser(Globals.OdjezdDate)+”
+ "" 
+ "";
byte[]byteArray=System.Text.Encoding.UTF8.GetBytes(postData);
Write(byteArray,0,byteArray.Length);
postStream.Close();
webRequest.BeginGetResponse(
新的异步回调(GetBookingFreeCapacityResponseCallback),
webRequest);//在此之后,我得到了异常
}
捕获(例外情况除外){}
}
私有静态无效GetBookingFreeCapacityResponseCallback(
IAsyncResult(异步结果)
{
试一试{
HttpWebRequest webRequest=
(HttpWebRequest)asynchronousResult.AsynchState;
//一些代码。。。
}
捕获(例外情况除外){}
}

你有什么建议是什么引起的吗?问题出在哪里?

一些用户遇到了相同的问题

在这种情况下,原因仍然不明

在本例中,原因是HTTP请求头中的非ASCII字符


另外,您不应该在非英语操作系统或IDE上开发。我99%确定你得到System.ArgumentException,但是你的“我用我的语言本地化了此异常名称”使得搜索解决方案和寻求帮助变得更加困难。

我创建了解决方案…创建新页面…

你有一个未处理的异常…好吧…但是…哪一个异常?它的错误消息是什么?它是System.EventArgs。异常的名称是:“参数不正确”(我用我的语言本地化了异常的名称,可能英文名称不同)。没有innerException和StackTrace…您说问题出在类型为
System.EventArgs
的参数上,但您没有发布接受或使用
EventArgs
EventArgs
派生参数的代码。您必须提供更多细节,比如异常中的堆栈跟踪。。。奇怪的是,当我第一次调用这个函数时,它还可以,但是在第二次调用时,我得到了这个异常。。。我应该为webRequest设置一些属性(close或我不知道)吗?这并不能回答这个问题。若要评论或要求作者澄清,请在他们的帖子下方留下评论-你可以随时对自己的帖子发表评论,一旦你有足够的评论,你就可以发表评论了。@Perception我同意这是一篇不好的帖子,但他是作者。我在GetBookingFreeCapacitydResponseCallback()中有一些错误的代码功能…我的错误…现在一切正常。。。