asp.net 后台 Http POST请求

时间忙,简单些,直接贴代码上图

百度站长平台为站长提供链接提交通道,您可以提交想被百度收录的链接,百度搜索引擎会按照标准处理 http://zhanzhang.baidu.com/linksubmit/

推送数据方法

  推送接口

  接口调用地址: http://data.zz.baidu.com/urls?site= wan.wangzhan.com.cn &token= M5nqw84uEyFIrr

 

  post推送示例

  POST /urls?site=wanmao.wangzhan360.com.cn&token=M5nqw84uEyFIrrkg HTTP/1.1
  User-Agent: curl/7.12.1 
  Host: data.zz.baidu.com 
  Content-Type: text/plain 
  Content-Length: 83 

http://www.example.com/1.html
http://www.example.com/2.html

查看推送反馈

推送成功

状态码为200,可能返回以下字段:

字段是否必选参数类型说明
success int 成功推送的url条数
remain int 当天剩余的可推送url条数
not_same_site array 由于不是本站url而未处理的url列表
not_valid array 不合法的url列表

成功返回示例:

{
    "remain":4999998,
    "success":2,
    "not_same_site":[],
    "not_valid":[]
}
推送失败
状态码为4xx,返回字段有:
字段是否必传类型说明
error int 错误码,与状态码相同
message string 错误描述

失败返回示例:

{
    "error":401,
    "message":"token is not valid"
}

推送代码:

 1 string postData = "http://www.chinasva.cn/HotNewsDetailed-14.html";
 2         string urls = "http://data.zz.baidu.com/urls?size=www.chinasva.com&token=CpayCbfg33ZeOI5d";
 3         // 要发放的数据
 4         
 5         byte[] byteArray = Encoding.UTF8.GetBytes(postData);
 6         HttpWebRequest objWebRequest = (HttpWebRequest)WebRequest.Create(urls);
 7       //  objWebRequest.ServicePoint.Expect100Continue = false;
 8         objWebRequest.Method = "POST";
 9         objWebRequest.ContentType = "text/plain";
10         objWebRequest.Host = "data.zz.baidu.com";
11         objWebRequest.UserAgent = "curl/7.12.1";
12         objWebRequest.ContentType = "text/plain";
13         //objWebRequest.ContentLength = 83;
14 
15         objWebRequest.ContentLength = byteArray.Length;
16         Stream newStream = objWebRequest.GetRequestStream();
17         // Send the data.
18         newStream.Write(byteArray, 0,postData.Length); //写入参数
19         newStream.Close();
20         HttpWebResponse response = (HttpWebResponse)objWebRequest.GetResponse();
21         StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.Default);
22         string textResponse = sr.ReadToEnd();
23         Response.Write(textResponse);
View Code


原文地址:https://www.cnblogs.com/itslives-com/p/HTTP_POST.html