1 public string Get(int id)
2 {
3
4 JObject o = new JObject(
5 new JProperty("billNo", "ESL1363593563"),
6 new JProperty("billType", "24"),
7 new JProperty("pageNo", "1"),
8 new JProperty("pageSize", "10"),
9 new JProperty("queryType ", "1")
10 );
11 //压缩str,用于得到sign的值
12 string str = "360buy_param_json" + o.ToString() + "access_token" + 123 + "app_key" + 123 + "method" + 123 + "timestamp=" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "v2.0";
13 //完整str
14 string str1 = "360buy_param_json=" + o.ToString() + "&access_token=" + 123 + "&app_key=" + 123 + "&method=" + 123 + "×tamp=" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "&v=2.0";
15
16 string end = "yourappSecret" + str + "yourappSecret";
17 string md5 = StrToMD5(end);//得出来sign
18 //最后拼接url:
19 string endstr = str1 + "&sign=" + md5;
20 //经常用到url中含有中文字符的需要对其进行字符串编码和解码,所以这里就用了这个System.Web.HttpUtility.UrlEncode,
21 c#asp.net url 传递中文参数要使用 System.Web.HttpUtility.UrlEncode 而不能使用Server.UrlEncode
22 string allStr = System.Web.HttpUtility.UrlEncode(endstr, System.Text.Encoding.UTF8);
23 byte[] bufferB = Encoding.UTF8.GetBytes(allStr);
24 System.Net.ServicePointManager.DefaultConnectionLimit = 200;
25 HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create("www.cctv.com");
26 WebReq.Method = "POST";
27 WebReq.ContentType = "application/x-www-form-urlencoded";
28 WebReq.ContentLength = allStr.Length;
29 Stream PostData = WebReq.GetRequestStream();
30 PostData.Write(bufferB, 0, bufferB.Length);
31 PostData.Close();
32
33 HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
34 StreamReader sr = new StreamReader(WebResp.GetResponseStream(), System.Text.Encoding.UTF8);
35 string backstr = sr.ReadToEnd();
36 backstr = HttpUtility.UrlDecode(backstr);
37 Console.WriteLine(WebResp.StatusCode);
38 Console.WriteLine(WebResp.Server);
39 Stream Answer = WebResp.GetResponseStream();
40 StreamReader _Answer = new StreamReader(Answer);
41 Console.WriteLine(_Answer.ReadToEnd());
42 return _Answer.ReadToEnd();
43
44 }