HttpWebRequest请求网站ajaxpro.ashx

qq_35151688 2018-12-18 03:22:14

这是工具抓包的

HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url.ToString());
byte[] data = Encoding.UTF8.GetBytes(json);
myRequest.CookieContainer = cookies;
myRequest.Method = "POST";
myRequest.Timeout = 30000;
myRequest.Referer = refs;
myRequest.Accept = "*/*";
myRequest.Headers["Accept-Language"] = "zh-CN,zh;q=0.9";
myRequest.Headers["X-AjaxPro-Method"] = method;
myRequest.Headers["Origin"] = "www.cnelc.com";
myRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36";
myRequest.ContentType = "text/plain; charset=utf-8";
myRequest.AllowAutoRedirect = true;
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
myResponse.Cookies = cookies.GetCookies(myResponse.ResponseUri);
cookies.Add(myResponse.Cookies);
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
string outdata = reader.ReadToEnd();
reader.Close();
myResponse.Close();
return outdata;

我的代码

返回的内容是{"error":{"Message":"obj","Type":"System.NotSupportedException"}}
...全文
262 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_35151688 2018-12-20
  • 打赏
  • 举报
回复
引用 7 楼 howze 的回复:
[quote=引用 6 楼 qq_35151688 的回复:]
这是一个发布信息的请求


你这个是在登陆状态下POST的?[/quote]请问这是什么情况
qq_35151688 2018-12-19
  • 打赏
  • 举报
回复
CookieContainer cookies = new CookieContainer();
public Image doGetImg()
{
try
{
string url = "http://www.cnelc.com/VerificationCode/CheckCode.aspx?Num=4";
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url.ToString());
myRequest.CookieContainer = cookies;
myRequest.Method = "GET";
myRequest.Accept = "image/webp,image/apng,image/*,*/*;q=0.8";
myRequest.Referer = "http://www.cnelc.com/user/Login.aspx";
myRequest.Headers.Add("Accept-Encoding", "gzip, deflate");
myRequest.Headers.Add("Accept-Language", "zh-CN,zh;q=0.9");
myRequest.KeepAlive = true;
myRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36";
myRequest.ContentType = "image/Gif; charset=utf-8";
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
myResponse.Cookies = cookies.GetCookies(myResponse.ResponseUri);
cookies.Add(myResponse.Cookies);
return Bitmap.FromStream(myResponse.GetResponseStream());
}
catch(Exception ex)
{
return null;
}
}

public string doPost()
{
try
{
string Url = "http://www.cnelc.com/user/Login.aspx";
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(Url.ToString());
myRequest.CookieContainer = cookies;
myRequest.Referer = " http://www.cnelc.com/user/Login.aspx";
myRequest.Method = "POST";
myRequest.Timeout = 30000;
myRequest.Headers["Cache-control"] = "max-age=0";
myRequest.Headers["Origin"] = "http://www.cnelc.com";
myRequest.Headers["Accept-Encoding"] = "gzip, deflate";
myRequest.Headers["Accept-Encoding"] = "zh-CN,zh;q=0.9";
myRequest.Headers["Upgrade-Insecure-Requests"] = "1";
myRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8";
string poststr = "__VIEWSTATE=%2FwEPDwUKMTg4NTQ0NDYzNWRkN9lElDjzvutr%2Fbh%2Bfa8%2B6a3sX2YR1jJ%2F4ZqhN2RhwCw%3D&__EVENTVALIDATION=%2FwEWBgLc%2B5HGBgKl1bKzCQKd%2B7qdDgLChPzDDQL07onSBgKgt7D9CtkAQM2nDOH0B%2BGNB1FadPmeXm4eRkF3K4BcsHI3U6Io&txtUserName=" + txtUserName.Text + "&txtPwd=" + txtPwd.Text + "&txtCode=" + txtCode.Text + "&bntLogin=";
byte[] data = Encoding.UTF8.GetBytes(poststr);
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
string outdata = reader.ReadToEnd();
myResponse.Cookies = cookies.GetCookies(myResponse.ResponseUri);
cookies.Add(myResponse.Cookies);
reader.Close();
if (outdata.Contains("该用户不存在"))
{
MessageBox.Show("该用户不存在");
}
else if (outdata.Contains("密码不正确"))
{
MessageBox.Show("密码不正确");
}
else if (outdata.Contains("验证码不正确"))
{
MessageBox.Show("验证码不正确");
}
return outdata;
}
catch (Exception ex)
{
return ex.Message;
}
}

这是登录的
qq_35151688 2018-12-19
  • 打赏
  • 举报
回复
嗯,登录之后的
howze 2018-12-19
  • 打赏
  • 举报
回复
引用 6 楼 qq_35151688 的回复:
这是一个发布信息的请求
你这个是在登陆状态下POST的?
qq_35151688 2018-12-19
  • 打赏
  • 举报
回复
这是一个发布信息的请求
qq_35151688 2018-12-19
  • 打赏
  • 举报
回复
http://www.cnelc.com/ajaxpro/CNELC.Main.Ajax.cnelc_ProductAjax,CNELC.Main.Ajax.ashx
howze 2018-12-19
  • 打赏
  • 举报
回复
引用 3 楼 qq_35151688 的回复:
请求的地址吗
对啊
qq_35151688 2018-12-19
  • 打赏
  • 举报
回复
请求的地址吗
howze 2018-12-19
  • 打赏
  • 举报
回复
网址发出来,帮你看看。
qq_35151688 2018-12-18
  • 打赏
  • 举报
回复
上面图是抓的HttpWebRequest请求的
这个是浏览器网站上的

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧