通过API传递数据 [英] Pass data through API

查看:176
本文介绍了通过API传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过asp.net mvc控制器发送数据,下面给出的php代码



例如PHP 

$ string ='{验证:[{ApiKey:}],ShipmentDetail:[{OriginCity:,ConsigneeName:,ConsigneeAddress:, ConsigneeEmail: , ConsigneeContact: , ShipmentReference: , DestinationCity: , Peices: , 重量: , FragileRequired: , InsuranceRequired :, CashCollectRequired: , ShipperComment: , CashCollect: , 产品详情: }]}';

$ result = file_get_contents(http://abc.com/portal/api/book.php?。urlencode($ string));





我的尝试:



我尝试通过下面给出的asp.net mvc控制器发送数据



 var formFields = new [] {
new KeyValuePair< string,string>(ApiKey,B855002463553A5B),
new KeyValuePair< string,string>(OriginCity,CKL),
new KeyValuePair< string,string>(ConsigneeName ,asif),
new KeyValuePair< string,string>(ConsigneeAddress,Mughalpura),
new KeyValuePair< string,string>(consigneeEmail,asif@gmail.com ),
new KeyValuePair< string,string>(ConsigneeContact,03344123546),
new KeyValuePair< string,string>(ConsigneeReference,Hassan),
new KeyValuePair< ; string,string>(DestinationCity,DGK),
new KeyValuePair< string,string>(Peices,1),
new KeyValuePair< string,string>(Weight 0.5),
新KeyValuePair< string,string>(FragileRequired,Y),
new KeyValuePair< string,string>(InsuranceRequired,N),
new KeyValuePair< string,string>(CashCollectRequired,Y),
new KeyValuePair< string,string>(ShipperComment,No),
new KeyValuePair< string,string>( CashCollect,1000),
新KeyValuePair< string,string>(ProductDetail,Special)
};
var postData = formFields.Aggregate(,(current,pair)=> current +(pair.Key +:+ HttpUtility.UrlEncode(pair.Value)+,));
var client = new WebClient();
client.Headers.Add(Content-Type,application / json);
var result = client.UploadString(http://abc.com/portal/api/book.php,postData);





以上代码给出错误错误的API密钥

解决方案

string ='{Validation:[{ApiKey:}],ShipmentDetail:[{OriginCity:,ConsigneeName:,ConsigneeAddress:, ConsigneeEmail : ConsigneeContact: , ShipmentReference: , DestinationCity: , Peices: , 重量: , FragileRequired: , InsuranceRequired :,CashCollectRequired:,ShipperComment:,CashCollect:,ProductDetail:}}}';


result =的file_get_contents( http://abc.com/portal/api/book.php? .urlencode(

串));





我的尝试:



我尝试通过下面给出的asp.net mvc控制器发送数据



 var formFields = new [] {
new KeyValuePair< string,string>(ApiKey,B855002463553A5B),
new KeyValuePair< string,string>(OriginCity,CKL),
new KeyValuePair< string,string>(ConsigneeName ,asif),
new KeyValuePair< string,string>(ConsigneeAddress,Mughalpura),
new KeyValuePair< string,string>(consigneeEmail,asif@gmail.com ),
new KeyValuePair< string,string>(ConsigneeContact,03344123546),
new KeyValuePair< string,string>(ConsigneeReference,Hassan),
new KeyValuePair< ; string,string>(DestinationCity,DGK),
new KeyValuePair< string,string>(Peices,1),
new KeyValuePair< string,string>(Weight 0.5),
新KeyValuePair< string,string>(FragileRequired,Y),
new KeyValuePair< string,string>(InsuranceRequired,N),
new KeyValuePair< string,string>(CashCollectRequired,Y),
new KeyValuePair< string,string>(ShipperComment,No),
new KeyValuePair< string,string>( CashCollect,1000),
新KeyValuePair< string,string>(ProductDetail,Special)
};
var postData = formFields.Aggregate(,(current,pair)=> current +(pair.Key +:+ HttpUtility.UrlEncode(pair.Value)+,));
var client = new WebClient();
client.Headers.Add(Content-Type,application / json);
var result = client.UploadString(http://abc.com/portal/api/book.php,postData);





以上代码给出错误错误的API密钥


I want to send data through asp.net mvc controller, php code given below

For Example in PHP 

$string = '{"Validation":[{"ApiKey":""}],"ShipmentDetail":[{"OriginCity":"","ConsigneeName":"","ConsigneeAddress":"","ConsigneeEmail":"","ConsigneeContact":"","ShipmentReference":"","DestinationCity":"","Peices":"","Weight":"","FragileRequired":"","InsuranceRequired":"","CashCollectRequired":"","ShipperComment":"","CashCollect":"","ProductDetail":""}]}'; 

$result = file_get_contents("http://abc.com/portal/api/book.php?".urlencode($string)); 



What I have tried:

I try to send data through asp.net mvc controller given below

var formFields = new[] {
           new KeyValuePair<string,string>("ApiKey","B855002463553A5B"),
           new KeyValuePair<string,string>("OriginCity","CKL"),
           new KeyValuePair<string,string>("ConsigneeName","asif"),
           new KeyValuePair<string,string>("ConsigneeAddress","Mughalpura"),
           new KeyValuePair<string,string>("ConsigneeEmail","asif@gmail.com"),
           new KeyValuePair<string,string>("ConsigneeContact","03344123546"),
           new KeyValuePair<string,string>("ConsigneeReference","Hassan"),
           new KeyValuePair<string,string>("DestinationCity","DGK"),
           new KeyValuePair<string,string>("Peices","1"),
           new KeyValuePair<string,string>("Weight","0.5"),
           new KeyValuePair<string,string>("FragileRequired","Y"),
           new KeyValuePair<string,string>("InsuranceRequired","N"),
           new KeyValuePair<string,string>("CashCollectRequired","Y"),
           new KeyValuePair<string,string>("ShipperComment","No"),
           new KeyValuePair<string,string>("CashCollect","1000"),
           new KeyValuePair<string,string>("ProductDetail","Special")
           };
           var postData = formFields.Aggregate("", (current, pair) => current + (pair.Key + ":" + HttpUtility.UrlEncode(pair.Value) + ","));
           var client = new WebClient();
           client.Headers.Add("Content-Type", "application/json");
           var result = client.UploadString("http://abc.com/portal/api/book.php", postData);



above code give error "Wrong API Key"

解决方案

string = '{"Validation":[{"ApiKey":""}],"ShipmentDetail":[{"OriginCity":"","ConsigneeName":"","ConsigneeAddress":"","ConsigneeEmail":"","ConsigneeContact":"","ShipmentReference":"","DestinationCity":"","Peices":"","Weight":"","FragileRequired":"","InsuranceRequired":"","CashCollectRequired":"","ShipperComment":"","CashCollect":"","ProductDetail":""}]}';


result = file_get_contents("http://abc.com/portal/api/book.php?".urlencode(


string));



What I have tried:

I try to send data through asp.net mvc controller given below

var formFields = new[] {
           new KeyValuePair<string,string>("ApiKey","B855002463553A5B"),
           new KeyValuePair<string,string>("OriginCity","CKL"),
           new KeyValuePair<string,string>("ConsigneeName","asif"),
           new KeyValuePair<string,string>("ConsigneeAddress","Mughalpura"),
           new KeyValuePair<string,string>("ConsigneeEmail","asif@gmail.com"),
           new KeyValuePair<string,string>("ConsigneeContact","03344123546"),
           new KeyValuePair<string,string>("ConsigneeReference","Hassan"),
           new KeyValuePair<string,string>("DestinationCity","DGK"),
           new KeyValuePair<string,string>("Peices","1"),
           new KeyValuePair<string,string>("Weight","0.5"),
           new KeyValuePair<string,string>("FragileRequired","Y"),
           new KeyValuePair<string,string>("InsuranceRequired","N"),
           new KeyValuePair<string,string>("CashCollectRequired","Y"),
           new KeyValuePair<string,string>("ShipperComment","No"),
           new KeyValuePair<string,string>("CashCollect","1000"),
           new KeyValuePair<string,string>("ProductDetail","Special")
           };
           var postData = formFields.Aggregate("", (current, pair) => current + (pair.Key + ":" + HttpUtility.UrlEncode(pair.Value) + ","));
           var client = new WebClient();
           client.Headers.Add("Content-Type", "application/json");
           var result = client.UploadString("http://abc.com/portal/api/book.php", postData);



above code give error "Wrong API Key"


这篇关于通过API传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆