asp.net 后台 Http POST请求

时间:2023-03-08 20:08:34

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

百度站长平台为站长提供链接提交通道,您可以提交想被百度收录的链接,百度搜索引擎会按照标准处理 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"
}
推送代码:
 string postData = "http://www.chinasva.cn/HotNewsDetailed-14.html";
string urls = "http://data.zz.baidu.com/urls?size=www.chinasva.com&token=CpayCbfg33ZeOI5d";
// 要发放的数据 byte[] byteArray = Encoding.UTF8.GetBytes(postData);
HttpWebRequest objWebRequest = (HttpWebRequest)WebRequest.Create(urls);
// objWebRequest.ServicePoint.Expect100Continue = false;
objWebRequest.Method = "POST";
objWebRequest.ContentType = "text/plain";
objWebRequest.Host = "data.zz.baidu.com";
objWebRequest.UserAgent = "curl/7.12.1";
objWebRequest.ContentType = "text/plain";
//objWebRequest.ContentLength = 83; objWebRequest.ContentLength = byteArray.Length;
Stream newStream = objWebRequest.GetRequestStream();
// Send the data.
newStream.Write(byteArray, ,postData.Length); //写入参数
newStream.Close();
HttpWebResponse response = (HttpWebResponse)objWebRequest.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.Default);
string textResponse = sr.ReadToEnd();
Response.Write(textResponse);