请求-有赞模拟登陆返回500错误

问题描述

有赞模拟登陆返回500错误 1C
我用浏览器打开时正常的,但是在程序中为什么就返回500错误了呢?具体代码如下:
地址:http://koudaitong.com/v2/account/user/login

 /// <summary>/// 获取验证码private void 登陆_Load(object sender EventArgs e){txtUserName.Text=""18076549077"";txtPwd.Text=""123456789"";GetViliCode();}private void pbCode_Click(object sender EventArgs e){GetViliCode();}/// <summary>/// 获取验证码/// </summary>public void GetViliCode(){var codeStr = ""http://koudaitong.com/captcha"";HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(codeStr);request.CookieContainer = MyCookies;HttpWebResponse response = (HttpWebResponse)request.GetResponse();Stream resStream = response.GetResponseStream();//得到验证码数据流Bitmap sourcebm = new Bitmap(resStream);//初始化Bitmap图片this.pbCode.Image = new Bitmap(sourcebm);}/// <summary>/// 登陆/// </summary>/// <param name=""sender""></param>/// <param name=""e""></param>private void btnLogin_Click(object sender EventArgs e){string userName = txtUserName.Text;string pwd = txtPwd.Text;string code = txtCode.Text;IDictionary<string string> loginParameter = new Dictionary<string string>();loginParameter.Add(""account"" userName);loginParameter.Add(""password"" pwd);loginParameter.Add(""captcha_code"" code);loginParameter.Add(""auto_login""on"");if (userName != """" && pwd != """" && code != """"){try{var cc = DoPost(loginUrl loginParameter ref MyCookieshttp://koudaitong.com/v2/account/user/login"");}catch (Exception ex){var bb = ex.Message;}}}public string DoPost(string url IDictionary<string string> parameters ref CookieContainer cookieContainer string referer){HttpWebRequest req = GetWebRequest(urlPOST"");System.Net.ServicePointManager.DefaultConnectionLimit = 2000;if (cookieContainer != null){req.CookieContainer = cookieContainer;}if (!string.IsNullOrEmpty(referer)){req.Referer = referer;}byte[] postData = Encoding.UTF8.GetBytes(BuildQuery(parameters));req.ContentType = ""application/x-www-form-urlencoded; charset=UTF-8"";req.ContentLength = postData.Length;req.UserAgent = ""Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML like Gecko) Chrome/39.0.2171.95 Safari/537.36"";req.Accept = ""application/json text/javascript */*; q=0.01"";Stream reqStream = req.GetRequestStream();reqStream.Write(postData 0 postData.Length);reqStream.Close();HttpWebResponse rsp = (HttpWebResponse)req.GetResponse();//垃圾回收// System.GC.Collect();Encoding encoding = Encoding.GetEncoding(rsp.CharacterSet);return GetResponseAsString(rsp encoding);}/// <summary>/// 组装普通文本请求参数。/// </summary>/// <param name=""parameters"">Key-Value形式请求参数字典</param>/// <returns>URL编码后的请求数据</returns>public static string BuildQuery(IDictionary<string string> parameters){StringBuilder postData = new StringBuilder();bool hasParam = false;if (parameters != null){IEnumerator<KeyValuePair<string string>> dem = parameters.GetEnumerator();while (dem.MoveNext()){string name = dem.Current.Key;string value = dem.Current.Value;if (hasParam){postData.Append(""&"");}postData.Append(name);postData.Append(""="");postData.Append(HttpUtility.UrlEncode(value Encoding.UTF8));hasParam = true;//}}}return postData.ToString();}}}

解决方案

url是
http://koudaitong.com/v2/account/user/login.json

时间: 2024-08-04 05:46:01

请求-有赞模拟登陆返回500错误的相关文章

windows-c#模拟登陆 返回500错误

问题描述 c#模拟登陆 返回500错误 我想用c#模拟登陆一个网站,然后再对网站进行操作,post参数也很简单,但是为什么返回500错误呢? using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Threading; namespace emulateLoginBaidu { clas

(HttpWebResponse)httpWebRequest.GetResponse() 总是返回500错误

问题描述 (HttpWebResponse)httpWebRequest.GetResponse()总是返回500错误,会是什么原因呢 解决方案 解决方案二:相同的地址浏览器上没问题解决方案三:是不是防火墙或者有权限设置啊?解决方案四:<!DOCTYPEhtml><html><head></head><body>Invalidactionclassconfigurationthatreferencesanunknownclassnamed[pho

请求facebook授权时,返回错误

在请求facebook授权时,返回如下错误:所提供的网址不被应用程序配置所接纳.:应用程序的设置不允许一个或多个所提供的链接.它必须与网站的URL或Canvas的URL相符,或该域必须是应用程序的一个域的子域. 解决:Facebook应用控制面板中"设置>高级"有" Valid OAuth redirect URIs"设置项,这里填写的地址要与程序中设置的授权返回页一致.

调用 RESTful API 创建聊天组返回 500 错误码

问题描述 调用 RESTful API 创建聊天组返回 500 错误,请帮忙给看看什么问题,谢谢.之前一直好好的,今天下午发现这样的错误比较多. ERROR - 2016-04-05 16:19:57 --> EaseMobClient: Reponse code not 200 while call easemob service : 500ERROR - 2016-04-05 16:19:57 --> EaseMobClient: Reponse content from easemob

python模拟登陆新浪微博,设置登录不需要验证码,代码返回验证码错误

问题描述 python模拟登陆新浪微博,设置登录不需要验证码,代码返回验证码错误 网页登陆不需要验证码 代码返回retcode=2070 验证码输入错误 求大神指点 解决方案 用fiddler调试下,看看是否带上了cookie,新浪是否传给你验证码,如果传了,必须先识别. 解决方案二: http://blog.csdn.net/ta790799213/article/details/44205351http://www.crazyant.net/796.htmlhttp://www.2cto.c

git学习------&amp;gt; 解决Gitlab 版本升级之后,发送 merge request 出现 http 500 的返回码错误

今天有同事在Gitlab上发送 Merge Request的时候,直接出现如下所示的界面,提示http 500,服务器内部出错. 一.错误描述 1.1 创建新的 Merge Request 1.2 填写 Merge Request 相关信息 1.3 发送 Merge Request ,出现500错误 1.4 登录管理员账户,在[Admin Area]–>[Monitoring]–>[Logs]–>[production.log]里面,搜索到错误信息如下所示: 错误描述部分信息如下: St

腾讯 微博 模拟登陆-腾讯微博模拟登陆成功,但请求code失败

问题描述 腾讯微博模拟登陆成功,但请求code失败 本科毕设做的腾讯微博抓取,最近项目交接给下一届时出现问题,发现腾讯微博模拟登陆成功,但请求code失败,返回信息意思是希望完成登陆,但是在这之前已经完成了登陆,抓包分析,cookie一致不缺失,苦于不知道问题到底在哪,各位有做这块的么,望解答,或加QQ:339071451,拜谢

网络爬虫-关于用python模拟登陆新浪微博返回内容

问题描述 关于用python模拟登陆新浪微博返回内容 第一次提交登陆信息和参数后,按照网上大神们的代码应该是在返回的内容中找到location.replace(....)提取url然后再访问,但是我post表单后得到的似乎不是登陆页面也不是正常登陆的页面 不知道这是一个什么页面...算是登陆上去了吗? 解决方案 基于python的新浪微博模拟登陆2014_新浪微博模拟登陆_python模拟新浪微博登陆---------------------- 解决方案二: 看上去是一个登录后的判断页面,要看你

正方系统爬虫,模拟登陆一直被重定向错误页面

问题描述 正方系统爬虫,模拟登陆一直被重定向错误页面 3C 302Response content: Object moved Object moved to here. 正方系统爬虫,在模拟登陆的时候,一直被重定向到这个页面,各位大神应该怎么解决这个问题