zoukankan      html  css  js  c++  java
  • 百度调价HttpWebRequest

    利用了tcpTrace,httpLook,好不容易搞定了,做下备份,以后就可以自己开发调价的软件了。原来准备用httpClient,但是httpClient是不支持POST,还是不支持Connection: Keep-Alive。反正用httpClient请求失败了。client.ServicePoint.Expect100Continue = false; 这个什么属性,弄了我3h的时间。备份下,以后自己用。

    Dictionary<string, string> cookiesTable = this.ConvertCookies(this.currentCookie);
    StringBuilder sb = new StringBuilder("path=");
    sb.Append(System.Web.HttpUtility.UrlEncode("MOD/").ToUpper());
    sb.Append("keyword");
    sb.AppendFormat("&userid={0}", cookiesTable["__cas__id__3"]);
    sb.AppendFormat("&token={0}", cookiesTable["__cas__st__3"]);
    sb.Append("&params={\"winfoid\":[\"1492927264\"],\"items\":{\"bid\":\"{price}\"}}".Replace("{price}", this.textBox1.Text));
    string postData = sb.ToString();
    byte[] data = System.Text.Encoding.UTF8.GetBytes(postData);

    HttpWebRequest client = (HttpWebRequest)HttpWebRequest.Create("http://fengchao.baidu.com/nirvana/request.ajax");

    client.Headers.Clear();

    //client.Headers.Add(HttpRequestHeader.Accept, "*/*");
    client.Headers.Add(HttpRequestHeader.AcceptLanguage, "zh-cn");
    client.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
    //client.Headers.Add(HttpRequestHeader.Host, "fengchao.baidu.com");
    //client.Headers.Add(HttpRequestHeader.Referer, "http://fengchao.baidu.com/nirvana/main.html?userid=797912#/manage/");
    client.Headers.Add(HttpRequestHeader.AcceptCharset, "GBK,utf-8;q=0.7,*;q=0.3");
    //client.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0E; .NET4.0C; InfoPath.2)");
    client.Headers.Add(HttpRequestHeader.CacheControl, "no-cache");
    //client.Headers.Add(HttpRequestHeader.ContentLength, postData.Length.ToString());
    //client.Headers.Add(HttpRequestHeader.Connection, "Keep-Alive");
    //client.Headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded");
    //client.Headers.Add(HttpRequestHeader.Cookie, this.currentCookie);

    client.Accept = "*/*";
    client.Referer = "http://fengchao.baidu.com/nirvana/main.html?userid=797912#/manage/";
    client.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0E; .NET4.0C; InfoPath.2)";
    //client.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
    client.ContentLength = data.Length;
    client.KeepAlive = true;
    client.ServicePoint.Expect100Continue = false;
    client.ContentType = "application/x-www-form-urlencoded";
    client.Headers.Add("x-request-by: baidu.ajax");
    client.Method = "POST";
    client.Headers.Add(HttpRequestHeader.Cookie, this.currentCookie);

    System.IO.Stream sw0 = client.GetRequestStream();
    sw0.Write(data, 0, data.Length);


    HttpWebResponse response = (HttpWebResponse)client.GetResponse();
    System.IO.Stream sw = response.GetResponseStream();
    System.IO.StreamReader reader = new System.IO.StreamReader(sw, System.Text.Encoding.UTF8);
    string result = reader.ReadToEnd();
    System.Diagnostics.Trace.Write(result);
    reader.Close();
    sw0.Close();
    sw.Close();
  • 相关阅读:
    MongoDB 副本集搭建 & 副本集扩容
    MongoDB 部署 & 基础命令
    MyBatis常见面试题:#{}和${}的区别是什么?
    MyBatis常见面试题:说说MyBatis的工作原理
    Java四种引用类型回收时机介绍
    Java虚拟机之垃圾回收器
    Servlet中过滤器、监听器和拦截器的区别
    Java里一个线程两次调用start()方法会出现什么情况
    二叉树、二叉查找树、平衡树和红黑树概念及其性质
    转:基于Redis实现延时队列
  • 原文地址:https://www.cnblogs.com/Linjianyu/p/2307783.html
Copyright © 2011-2022 走看看