C#中的POST请求参数问题
||
每当用户单击日历以更改日期时,该网站就会使用POST发送数据。我使用Firebug进行了检查。目标URL是这个。特定示例的发布数据(以空格分隔)为“ 0”。
这是标题:
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)。
没有找到相关结果
已邀请:
2 个回复
扦帽次杏
惭法搽