问题描述
usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.IO;usingSystem.Net;namespaceMyLogin{classPostGetWebRequest{publicstringLoginUrl;//privateCookieContainerMyCookieContainer;privateHttpWebRequestrequest;privateHttpWebResponseresponse;privateStreamstream;privateStreamReaderstreamReader;privatestringSrc="";privatestringpostData;publicstringHtmlUserName;publicstringHtmlPassword;//privatestringHtmlSubmit;publicstringPostWebRequest(){request=(HttpWebRequest)WebRequest.Create(LoginUrl);MyCookieContainer=newCookieContainer();//设置提交相关参数postData="email="+HtmlUserName.Replace("@","%40")+"&password="+HtmlPassword+"&origURL="+LocationUrl+"&domain=renren.com";ASCIIEncodingencoding=newASCIIEncoding();byte[]data=encoding.GetBytes(postData);request.Method="POST";request.ContentType="application/x-www-form-urlencoded";request.ContentLength=data.Length;request.KeepAlive=false;request.CookieContainer=MyCookieContainer;//把取服务器发给客户端跟session想对应的cookie;相当于是一个容器//提交请求stream=request.GetRequestStream();stream.Write(data,0,data.Length);stream.Close();//接收response=(HttpWebResponse)request.GetResponse();streamReader=newStreamReader(response.GetResponseStream(),Encoding.UTF8);Src=streamReader.ReadToEnd();streamReader.Close();stream.Close();returnSrc;}}classProgram{staticvoidMain(string[]args){PostGetWebRequestpostGetWebRequest=newPostGetWebRequest();//没有验证码的网站,登录页面html格式,客户端的postGetWebRequest.HtmlUserName="xxx@163.com";postGetWebRequest.HtmlPassword="aaaaaa";postGetWebRequest.LoginUrl="http://www.renren.com/PLogin.do";//这个是人人的登录页stringcontent1=postGetWebRequest.PostWebRequest();Console.WriteLine(content1);Console.ReadKey();}}}问题是我想获得post后响应的正文比如{"code":true,"homeUrl":"http://www.renren.com/callback.do?t=35466507bb49807292e00bbe5063b9090&origURL=http%3A%2F%2Fwww.renren.com%2Fhome&needNotify=false"}我该怎么修改代码??
解决方案
解决方案二:
什么意思,content1不是返回的内容吗,如果想post其他地址,就修改url那个网站需要提交的参数,每个页面的参数可能不一样,你先抓包看看都提交了哪些,自己对着组织
解决方案三:
我运行后返回了一段登录前页面的源代码,但我无法判断是否登录成功啊,如果我能得到post的响应正文就可以,问题是怎么获得?
解决方案四:
{"code":true,"homeUrl":"http://www.renren.com/callback.do?t=35466507bb49807292e00bbe5063b9090&origURL=http%3A%2F%2Fwww.renren.com%2Fhome&needNotify=false"}这是登录成功的{"catchaCount":1,"code":false,"homeUrl":"http://www.renren.com/SysHome.do?origURL=http%3A%2F%2Fwww.renren.com%2Fhome&catchaCount=1&failCode=128","failDescription":"您的用户名和密码不匹配","failCode":128,"email":"18986143802"}这是登录失败的我该怎么获取这段代码?