#region << 版 本 注 释 >>
/*
* ========================================================================
* CLR版本 :4.0.30319.42000
* 类 名 称:BDAPIStoreHelper
* 机器名称:ENGOO-YPF
* 命名空间:YPF.Common.Web处理
* 文 件 名:BDAPIStoreHelper
* 创建时间:2016/12/14 17:55:21
* 作 者:杨朋飞
* 说 明:
* 修改时间:
* 修 改 人:
* ========================================================================
*/
#endregion
using System.IO;
using System.Net;
using System.Text;
using System.Web.Script.Serialization;
namespace YPF.Common.Web处理
{
/// <summary>
/// 百度APIStore调用帮助类
/// </summary>
public class BDAPIStoreHelper
{
/// <summary>
/// 发送HttpPost请求
/// </summary>
/// <param name="url">请求的URL</param>
/// <param name="param">请求的参数</param>
/// <param name="apikey">您自己的apikey</param>
/// <returns>请求结果(json对象)</returns>
public static object Post(string url, string param, string apikey)
{
string strURL = url;
HttpWebRequest request;
request = (HttpWebRequest)WebRequest.Create(strURL);
request.Method = "POST";
// 添加header
request.Headers.Add("apikey", apikey);
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<object>(strValue);
}
}
//示例调用
//string url = "http://apis.baidu.com/idl_baidu/baiduocrpay/idlocrpaid";
//string param = "参数1=值1&参数2=值2&参数3=值3。。。。。。。";
//string result = request(url, param);
}
/// <summary>
/// 发送HttpGet请求
/// </summary>
/// <param name="url">请求的URL</param>
/// <param name="param">请求的参数</param>
/// <param name="apikey">开发者apikey</param>
/// <returns>请求结果(json对象)</returns>
public static object Get(string url, string param, string apikey)
{
string strURL = url + '?' + param;
HttpWebRequest request;
request = (HttpWebRequest)WebRequest.Create(strURL);
request.Method = "GET";
// 添加header
request.Headers.Add("apikey", apikey);
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<object>(strValue);
}
}
}
}
百度APIStore接口访问c#版
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 本篇演示 Table parameter 作为输出参数时的处理方法。要用到的函数是 BAPI_COMPANYCOD...