首页 新闻 赞助 找找看

关于asp.net post提交数据的问题

0
[已关闭问题]

我想提交一段html代码到:http://validator.w3.org/#validate_by_input.然后获取他的验证结果

我用http watch看了下,post的格式为:

doctype    Inline
fragment    test html code
group    0
prefill    0
prefill_doctype    html401

我的代码如下:

string _validateSite = "http://validator.w3.org/check";
String _postStr = "doctype=Inline&fragment" + this.txb.Text+"&group=0&prefill=0&prefill_doctype=html401";
 string _strResult = "";
            try
            {
                byte[] _byte = System.Text.Encoding.UTF8.GetBytes(_postData);
                HttpWebRequest _httpRequest = (HttpWebRequest)WebRequest.Create(_url);
                _httpRequest.ContentType = "application/x-www-form-urlencoded";
                _httpRequest.ContentLength = _byte.Length;
                _httpRequest.Method = "POST";
                Stream _postStream = _httpRequest.GetRequestStream();
                _postStream.Write(_byte, 0, _byte.Length);
                _postStream.Close();

                HttpWebResponse _response = (HttpWebResponse)_httpRequest.GetResponse();
                Stream _streamReceive = _response.GetResponseStream();
                Encoding _encoding = Encoding.GetEncoding("UTF-8");
                StreamReader _streamReader = new StreamReader(_streamReceive, _encoding);
                _strResult = _streamReader.ReadToEnd();

            }
            catch (Exception err)
            {
                _strResult = err.Message;
            }

            return _strResult;

 

发现监控我程序的post数据格式为:

__EVENTVALIDATION /wEWAwLeq5XpBgKMx9HrBwKM54rGBjWkVy5dxqfO4J8maqnNmQjYcmkH


__VIEWSTATE    /wEPDwUKMTkwNjc4NTIwMWRkR7CqFW2X0Z/oejoy2A+0tQIg/8U=
Button1    Button
txb     test html code

 

然后验证结果总是跟直接在他的site上验证的不一样,要么显示文档不可识别,要么就是只验证我提交了部分html代码

 

请问这是怎么回事呢?谢谢

 

 

问题补充: 第二行改成这样,还是不行 String _postStr = "doctype=Inline&fragment=" + this.txb.Text+"&group=0&prefill=0&prefill_doctype=html401";
charlie的主页 charlie | 初学一级 | 园豆:4
提问于:2008-12-30 22:01
< >
分享
其他回答(1)
0

会不会模拟时有些参数你没有设定,这个模拟的比较象,你检查一下看看:

http://space.cnblogs.com/question/4351/

GUO Xingwang | 园豆:3885 (老鸟四级) | 2008-12-31 12:05
0

你可以用一定的工具想:httpwatch截取post的数据,包括cookie等内容。一般都屡试不爽

LittlePeng | 园豆:3445 (老鸟四级) | 2009-01-02 13:00
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册