百度鹰眼 html,百度鹰眼接口访问c#版

using System.IO;

using System.Net;

using System.Text;

using System.Web.Script.Serialization;

///

/// 百度鹰眼调用帮助类

///

public class BDYingYanAPIHelper

{

///

/// 发送HttpPost请求

///

/// 请求的URL

/// 请求的参数。(参数1=值1&参数2=值2&参数3=值3。。。。。。。)

/// 请求结果(json对象)

public static object Post(string url, string param)

{

string strURL = url;

HttpWebRequest request;

request = (HttpWebRequest)WebRequest.Create(strURL);

request.Method = "POST";

request.ContentType = "application/x-www-form-urlencoded";

string paraUrlCoded = param;

byte[] payload;

payload = Encoding.UTF8.GetBytes(paraUrlCoded);

request.ContentLength = payload.Length;

using (Stream writer = request.GetRequestStream())

{

writer.Write(payload, 0, payload.Length);

HttpWebResponse response;

response = (HttpWebResponse)request.GetResponse();

Stream s;

s = response.GetResponseStream();

string StrDate = "";

string strValue = "";

using (StreamReader Reader = new StreamReader(s, Encoding.UTF8))

{

while ((StrDate = Reader.ReadLine()) != null)

{

strValue += StrDate + "\r\n";

}

JavaScriptSerializer js = new JavaScriptSerializer();

return js.Deserialize(strValue);

}

}

//示例调用

//string url = "http://apis.baidu.com/idl_baidu/baiduocrpay/idlocrpaid";

//string param = "参数1=值1&参数2=值2&参数3=值3。。。。。。。";

//string result = Post(url, param);

}

///

/// 发送HttpGet请求

///

/// 请求的URL

/// 请求的参数

/// 开发者apikey

/// 请求结果(json对象)

public static object Get(string url, string param)

{

string strURL = url + '?' + param;

HttpWebRequest request;

request = (HttpWebRequest)WebRequest.Create(strURL);

request.Accept = @"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";

request.ContentType = "application/json; charset=utf-8";

request.Method = "GET";

// 添加header

HttpWebResponse response;

response = (HttpWebResponse)request.GetResponse();

Stream s;

s = response.GetResponseStream();

string StrDate = "";

string strValue = "";

using (StreamReader Reader = new StreamReader(s, Encoding.UTF8))

{

while ((StrDate = Reader.ReadLine()) != null)

{

strValue += StrDate + "\r\n";

}

JavaScriptSerializer js = new JavaScriptSerializer();

return js.Deserialize(strValue);

}

//示例调用

//string url = "http://apis.baidu.com/idl_baidu/baiduocrpay/idlocrpaid";

//string param = "参数1=值1&参数2=值2&参数3=值3。。。。。。。";

//string result = Get(url, param);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值