当前位置:编程学习 > C#/ASP.NET >>

httpwebreques模拟站内发信,总是失败

这是网站发信的原始抓包数据:
POST /msg/dosend.php HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/QVOD, application/QVOD, application/xaml+xml, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-xpsdocument, */*
Referer: http://www.jiayuan.com/msg/send.php?uhash=b2afb6fd8489c0ec1a2b63342989dddf&from=match_list_result_t10&fxly=tj-xsp-jrsp-page
Accept-Language: zh-cn
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; 4399Box.720; .NET CLR 2.0.50727; .NET4.0C; .NET4.0E; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; AE8)
Host: www.jiayuan.com
Content-Length: 305
Connection: Keep-Alive
Pragma: no-cache
Cookie: PHPSESSID=4183e41bdd748021064a556cfc22c0a0; ip_loc=33; view_m=1; main_search:92525078=%7C%7C%7C00; SESSION_HASH=81b1dd4ea5a06c91697e8d72cbe178a9d4dd0890; stadate1=91525078; myloc=37%7C3702; myage=22; PROFILE=92525078%3A%25E6%259B%25BE%25E6%25AA%2580%25E9%259B%2585%3Am%3Aphotos1.jiayuan.com%2F01%2F07%2Ff5e8aa795d55a324f8a9c672366d%3A0%3A%3Ahttp%3A%2F%2Fimages1.jyimg.com%2Fw4%2Fglobal%2Fi%2Fnopic_m.jpg%3A1; my易做图=m; myuid=91525078; myincome=10; RAW_HASH=bee9b6151c3cc9e1c37d8988b7d1a61fc4ca6ab7; COMMON_HASH=01f5e8aa795d55a324f8a9c672366d07; sl_jumper=%26cou%3D17%26omsg%3D0%26dia%3D0%26lst%3D2013-06-10; last_login_time=1370841137; new_msg=0; IM_S={"IM_CID":4622130,"svc":{"code":0,"nps":0,"unread_count":"1","ocu":0,"ppc":0,"jpc":0,"using":"","uid":92525078}}; IM_CS=2; IM_ID=2; pop_1361757808=1370855548437; pclog={"92525078":"1370841148750|0|0"}; IZ_bind92525078=0; IM_TK=1370841181328; pop_time=1370841177578

contents=nice+to+meet+you&picture=http%3A%2F%2F&ok_xinzhi_id=&fxly=tj-xsp-jrsp-page&reply_msgid=0&reply_send_time=0&to_hash=b2afb6fd8489c0ec1a2b63342989dddf&now_draft_id=0&need_fxtyp_tanchu=0&self_pay=0&fxbc=0&cai_xin=0&liwu_nofree=0&liwu_nofree_id=817&liwu_free=1&liwu_free_id=1113&moban_type=9&zhuanti=0
这是我写的代码发信的抓包数据:
POST /msg/send.php HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.84 Safari/535.11 SE 2.X MetaSr 1.0
Content-Type: text/html; charset=UTF-8
Host: www.jiayuan.com
Cookie: myloc=37%7C3702; myage=22; PROFILE=92525078%3A%25E6%259B%25BE%25E6%25AA%2580%25E9%259B%2585%3Am%3Aphotos1.jiayuan.com%2F01%2F07%2Ff5e8aa795d55a324f8a9c672366d%3A0%3A%3Ahttp%3A%2F%2Fimages1.jyimg.com%2Fw4%2Fglobal%2Fi%2Fnopic_m.jpg%3A1; my易做图=m; myuid=91525078; myincome=10; SESSION_HASH=2238a03b3f16502c7ce58e161e79dff2fc69b714; RAW_HASH=bee9b6151c3cc9e1c37d8988b7d1a61fc4ca6ab7; COMMON_HASH=01f5e8aa795d55a324f8a9c672366d07; sl_jumper=%26cou%3D17%26omsg%3D0%26dia%3D0%26lst%3D2013-06-12; last_login_time=1371013726; PHPSESSID=e58ec15ae005a0d2f596a8cc9b9dce47; main_search:92525078=%7C%7C%7C00; ip_loc=33; view_m=1; new_msg=0; IM_CS=2; IM_ID=4; IZ_bind92525078=0; IM_M=[]
Content-Length: 365
Expect: 100-continue

contents=%E4%BD%A0%E5%A5%BD%EF%BC%8C%E8%83%BD%E8%AE%A4%E8%AF%86%E4%BD%A0%E5%90%97%EF%BC%9F&picture=http%3A%2F%2F&ok_xinzhi_id=&fxly=cp-eexpress&reply_msgid=0&reply_send_time=0&to_hash=cd5e51d119a9b094851d687fb63fe73b&now_draft_id=0&need_fxtyp_tanchu=0&self_pay=0&fxbc=0&cai_xin=0&liwu_nofree=0&liwu_nofree_id=585&liwu_free=1&liwu_free_id=1099&moban_type=9&zhuanti=0

返回提示无效的UE ID:
<dt><strong>发送信件错误</strong><br />无效的用户编号</dt>

模拟post里面cookie有几个是获取不到,就没写。
有没有写过类似站内发信的? c# post --------------------编程问答-------------------- 看起来似乎是Cookie的那段josn的问题
主要是这段没有写入到Cookie,然后程序没有读取到相关的参数 --------------------编程问答--------------------
引用 1 楼 fei2yun 的回复:
看起来似乎是Cookie的那段josn的问题
主要是这段没有写入到Cookie,然后程序没有读取到相关的参数
你是说这段吗?
 IM_S={"IM_CID":4622130,"svc":{"code":0,"nps":0,"unread_count":"1","ocu":0,"ppc":0,"jpc":0,"using":"","uid":92525078}}; IM_CS=2; IM_ID=2; pop_1361757808=1370855548437; pclog={"92525078":"1370841148750|0|0"}; IZ_bind92525078=0; IM_TK=1370841181328; pop_time=1370841177578
这段获取不到啊。 --------------------编程问答-------------------- 这段肯定不是获取的
而是提交,必须要写入到cookie之后,才可以

估计是这段的问题,其他的似乎不存在什么。

PS:我怀疑这个是一个登录的JOSN,也就是验证
可以先模拟用户登录一次,然后再提交POST的数据过去。 --------------------编程问答--------------------
引用 3 楼 fei2yun 的回复:
这段肯定不是获取的
而是提交,必须要写入到cookie之后,才可以

估计是这段的问题,其他的似乎不存在什么。

PS:我怀疑这个是一个登录的JOSN,也就是验证
可以先模拟用户登录一次,然后再提交POST的数据过去。

在post上面数据之前,登陆过了,上面没贴出来。这是模拟登陆的数据:
GET /login/jump/?cb=9YB3RC2RC9MQbZtroFFUu18x-L51WocGUnQD45XV5rFzIVD*LHmDQ*2HzfwgQO2hyENQ*FaShTE-Vc3vqd75733jgSeOXZ4PEevW8hpN1PmWl*ngOcjwUDp0nkcygTRGv5lxa4OeveeyKiTYvIKsQr4Rez-t7LGIASkOvoLyrY4id1bwxWVMkEMvaW7SSMIc81OdHWyRGoe9QYJ0Ng92WMZH9Kfr*qIP00mBM7xZws7X3QnCdHB2*eIxJVUHRZ*eYRfZQQBeubvNoKa0uAe0ZJr21bWmbwPQHCMigW3vKveQ2oUVToGJc8Q-If9esyuKRPbAbthRsDN95Kn3u68AEeABTdT6197YGS9kNMQJXC162FUJdXGCypIO4Yjt9bvJdWokAGsKXAkzOjlExF7qBB0OrJQrpKsdmryXrgF3atlbyBWj3LEO0g9ItHudk5QiMijhYEHlAseC2eaqAUOfdqvGYu6sXphNhfAF4Cy2927CLM5Hzd8LZpwV3KFd5e4QUhxAiTSdoUjliAXeIbA7Rr37-SUd2rCldHTW5Lue5ZLyO2UhOFkNkSWVX5RjdG0qCaVMZ3l14PTgW1rdz7Ive7BbWIk7ZZ3cokT0UW8AsMDGhLUiUn6wDwWhX37FlKjJS7iD1fjj5BDlOmVYCm2xBQE HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Accept: */*
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; 4399Box.720; .NET CLR 2.0.50727; .NET4.0C; .NET4.0E; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; AE8)
Host: www.jiayuan.com
Cookie: stadate1=91525078; myloc=37%7C3702; myage=22; PROFILE=92525078%3A%25E6%259B%25BE%25E6%25AA%2580%25E9%259B%2585%3Am%3Aphotos1.jiayuan.com%2F01%2F07%2Ff5e8aa795d55a324f8a9c672366d%3A0%3A%3Ahttp%3A%2F%2Fimages1.jyimg.com%2Fw4%2Fglobal%2Fi%2Fnopic_m.jpg%3A1; my易做图=m; myuid=91525078; myincome=10; SESSION_HASH=2238a03b3f16502c7ce58e161e79dff2fc69b714; RAW_HASH=bee9b6151c3cc9e1c37d8988b7d1a61fc4ca6ab7; COMMON_HASH=01f5e8aa795d55a324f8a9c672366d07; sl_jumper=%26cou%3D17%26omsg%3D0%26dia%3D0%26lst%3D2013-06-12; last_login_time=1371013726
看响应是成功了:
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 12 Jun 2013 05:08:46 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive

9f5
 <!DOCTYPE html><html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title>登录成功</title> --------------------编程问答-------------------- 看你代码
HttpWebRequest的CookieContainer参数看了么?
CookieContainer CookieHwr = new CookieContainer();
myRequest.CookieContainer = CookieHwr;

--------------------编程问答--------------------
引用 5 楼 fei2yun 的回复:
看你代码
HttpWebRequest的CookieContainer参数看了么?
CookieContainer CookieHwr = new CookieContainer();
myRequest.CookieContainer = CookieHwr;
cookie参数咋啦?
这个cookie是login之后从响应中提取的啊:
          CookieContainer cookie = new CookieContainer();
          cookie =  GetCooKie("http://passport.jiayuan.com/dologin.php", "name=7OT691XGZ%40163.com&password=EA2S897GIe5", header);

后面再加些能其他能得到的cookie值。 --------------------编程问答-------------------- 这是fiddler抓的包,有高人指点一下不?
正常网页抓的包:http://dl.vmall.com/c0ovbck2ui
代码模拟抓的包:http://dl.vmall.com/c07vabfilh --------------------编程问答-------------------- 你qq多少啊。。交流下
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,