C# C语言中请求后参数的问题#

C# C语言中请求后参数的问题#,c#,http,post,httpwebrequest,webrequest,C#,Http,Post,Httpwebrequest,Webrequest,当用户点击日历更改日期时,网站使用POST发送数据。我用萤火虫检查它。目标URL为。特定示例的post数据(空格分隔)是LeagueID=9 GameDate=4-29-2011 Season=2010-2011刷新=false LastUpdateTime=01-01-1900 type=matchips RefreshStartTime=15-5-2011-1308094688683 Week=conferenceID= 以下是标题: Host scores.covers.com Us

当用户点击日历更改日期时,网站使用POST发送数据。我用萤火虫检查它。目标URL为。特定示例的post数据(空格分隔)是
LeagueID=9 GameDate=4-29-2011 Season=2010-2011刷新=false LastUpdateTime=01-01-1900 type=matchips RefreshStartTime=15-5-2011-1308094688683 Week=conferenceID=

以下是标题:

Host    scores.covers.com
User-Agent  Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language en-gb,en;q=0.5
Accept-Encoding gzip, deflate
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive  115
Connection  keep-alive
Referer http://scores.covers.com/basketball-scores-matchups.aspx
Content-Length  169
Content-Type    text/plain; charset=UTF-8
Cookie  __loooooooooongCookieString
我想使用
WebRequest
(或者其他任何方法)发出POST请求。以下是我的尝试:

        string parameters = "LeagueID=\"9\"&GameDate=\"4-29-2011\"&Season=\"2010-2011\"&Refresh=\"false\"&LastUpdateTime=\"01-01-1900\"&type=\"Matchups\"&RefreshStartTime=\"15-5-2011-1308094688683\"&Week=&conferenceID=";
        byte[] bytes = Encoding.ASCII.GetBytes(parameters);

        HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://scores.covers.com/ajax/SportsDirect.Controls.LiveScoresControls.Scoreboard,SportsDirect.Controls.LiveScoresControls.ashx?_method=UpdateScoreboard&_session=no");


        req.Method = "POST";
        req.ContentLength = bytes.Length;
        req.ContentType = "text/plain; charset=UTF-8";
        Console.WriteLine(req.ContentLength); // 175

        Stream reqStream = req.GetRequestStream();
        reqStream.Write(bytes, 0, bytes.Length);
        reqStream.Close();

        WebResponse resp = req.GetResponse();
        Console.WriteLine(((HttpWebResponse)resp).StatusDescription); // OK

        Stream respStream = resp.GetResponseStream();
        StreamReader reader = new StreamReader(respStream);
        Console.WriteLine(reader.ReadToEnd());
        resp.Close();
但它不起作用。响应代码正常,但响应本身如下:

new Object();r.error = new ajax_error('System.FormatException','Input string was
 not in a correct format.\r\nCould not retreive parameters from HTTP request.',0
)new Object();r.error = new ajax_error('System.ArgumentException','Object of typ
e \'System.DBNull\' cannot be converted to type \'System.Int32\'.',0)

怎么回事?我可以看出参数有问题,因为请求的内容长度是175(与Firefox请求的169相反)。

以后指定UTF-8时不要进行ASCII编码。确保url编码参数。尝试将内容类型更改为“x-www-form-urlencoded”。

以后指定UTF-8时不要进行ASCII编码。确保url编码参数。请尝试将内容类型更改为“x-www-form-urlencoded”。

为什么不使用来发布参数?它为你做了一些棘手的事情。链接页面底部的代码非常简单。与示例不同的是,您可能应该深思熟虑地处理WebClient的处理。

为什么不使用?它为你做了一些棘手的事情。链接页面底部的代码非常简单。与示例不同,您可能应该仔细处理WebClient的处置