HttpClient
HttpClient client = new HttpClient();
client = new HttpClient();
client.BaseAddress = new Uri(string.Concat("http://cloudapi.beimai.com", "/"));
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
string pstr = "{\"page\":1,\"pagesize\":10}";
string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
string sign=Tool.SignHelper.Sign("access_token=" + access_token + "&app_key=1001&bm_param="+pstr+"×tamp="+ timestamp, "從第三方平臺獲取");
/*=====================兩種方式針對不同的接口使用不同的調(diào)用方式===================*/
//下訂單采購單等數(shù)據(jù)提交類的,使用以下代碼,如:
var content = new FormUrlEncodedContent(new Dictionary<string, string>() {
{ "SourceId", orderItem.SourceId.ToString() },
{ "SourceOrderId", orderItem.SourceOrderId } ,
{ "ReceiveWay", orderItem.ReceiveWay.ToString() } ,
{ "ProvinceId", orderItem.ProvinceId.ToString() } ,
{ "CityId", orderItem.CityId.ToString() } ,
{ "AreaId", orderItem.AreaId.ToString() },
{ "Address", orderItem.Address } ,
{ "ZipCode", orderItem.ZipCode } ,
{ "Receiver", orderItem.Receiver} ,
{ "TelPhone", orderItem.TelPhone } ,
{ "OrderTotal", orderItem.OrderTotal.ToString() },
{ "ProductAmount", orderItem.ProductAmount.ToString() } ,
{ "IsOpenInvoice", orderItem.IsOpenInvoice.ToString() } ,
{ "PList", pstr }
});
HttpResponseMessage response02 = client.PostAsync("api/order/placeorder?app_key=1001&access_token=" + HttpUtility.UrlEncode(token.access_token) + "&sign=" + HttpUtility.UrlEncode(sign), content).Result;
//非數(shù)據(jù)提交類的,使用以下調(diào)用方式,如:
HttpResponseMessage response02 = client.PostAsync("api/ps/gsbmpd?app_key=1001&access_token=" + HttpUtility.UrlEncode(access_token) +
"&sign=" + HttpUtility.UrlEncode(sign) + "&bm_param=" + HttpUtility.UrlEncode(pstr) + "×tamp=" + HttpUtility.UrlEncode(timestamp), null).Result;
/*=====================兩種方式針對不同的接口使用不同的調(diào)用方式===================*/
object obj=null;
if (response02.IsSuccessStatusCode)
{
obj = response02.Content.ReadAsAsync<object>().Result;
}
然后提取json對象中的result 即可,可分頁循環(huán)處理直到取不到結(jié)果為止。