Передача данных через API
Я хочу отправить данные через asp.net контроллер mvc, php-код приведен ниже
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));
Что я уже пробовал:
Я пытаюсь отправить данные через 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"), 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);
приведенный выше код выдает ошибку " неправильный ключ API"