System.Net.ServicePointManager.Expect100Continue = false;
现在,当我尝试使用POST登录时,我收到此错误:
You don’t seem to accept cookies. cookies are required in order to log in. Help
我已经尝试了几次,并且用Google搜索,我仍然无法登录Hotfile.com ..我的代码是这样的:
string response;byte[] buffer = EnCoding.ASCII.GetBytes("user=XX&pass=XX");cookieContainer cookies = new cookieContainer();httpWebRequest WebReq = (httpWebRequest)WebRequest.Create("http://hotfile.com/login.PHP");WebReq.Credentials = new NetworkCredential("XX","XX");WebReq.PreAuthenticate = true;WebReq.Pipelined = true;WebReq.cookieContainer = cookies;WebReq.KeepAlive = true;WebReq.Method = "POST";WebReq.ContentType = "application/x-www-form-urlencoded";WebReq.ContentLength = buffer.Length;WebReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; windows NT 6.0; SLCC1)";Stream PostData = WebReq.GetRequestStream();PostData.Write(buffer,buffer.Length);PostData.Close();httpWebResponse WebResp = (httpWebResponse)WebReq.GetResponse();Stream Answer = WebResp.GetResponseStream();StreamReader _Answer = new StreamReader(Answer);response = _Answer.ReadToEnd();file.WriteallText("dump.HTML",response);
当然,用户和通行证将拥有您的帐户值.
解决方法 这是我为您写的一个工作示例:var cookies = new cookieContainer();ServicePointManager.Expect100Continue = false;var request = (httpWebRequest)WebRequest.Create("http://www.hotfile.com/login.PHP");request.cookieContainer = cookies;request.Method = "POST";request.ContentType = "application/x-www-form-urlencoded";using (var requestStream = request.GetRequestStream())using (var writer = new StreamWriter(requestStream)){ writer.Write("user=XX&pass=XX&returnto=/");}using (var responseStream = request.GetResponse().GetResponseStream())using (var reader = new StreamReader(responseStream)){ var result = reader.ReadToEnd(); Console.Writeline(result);}总结
以上是内存溢出为你收集整理的c# – .NET HTTP POST方法 – Cookie问题全部内容,希望文章能够帮你解决c# – .NET HTTP POST方法 – Cookie问题所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)