我必须在我的代码中集成Ecom express shipping API。此api用于在订购时预先生成AWB编号。以下是整合shipping api的文档说明:
测试服务器网址:Create or run a macro
测试服务器凭据:用户名:ecomexpress密码:Ke $ 3c @ 4oT5m6h#$
示例请求正文:
对于PPD 用户名= ecomexpress&安培;密码=柯$ 3C @ 4oT5m6h#$&安培;计数= 1&安培;类型= PPD 对于COD 用户名= ecomexpress&安培;密码=柯$ 3C @ 4oT5m6h#$&安培;计数= 1&安培;类型= COD
此API适用于邮递员并生成AWB编号,但尝试使用C#代码会产生空对象。
在这里查看我正在使用的代码:
var client = new HttpHandler.Client("http://staging.ecomexpress.in/apiv2/fetch_awb/");
var newUrl = "http://staging.ecomexpress.in/apiv2/fetch_awb/?username=ecomexpress&password=Ke$3c@4oT5m6h#$&count=1&type=PPD";
var data = client.PostData<dynamic>(newUrl, new { username= "ecomexpress", password= "Ke$3c@4oT5m6h#$", count=1,type= "PPD" });
if (data!=null){ // do some stuff here }
我正在使用http处理程序nuget包(http://staging.ecomexpress.in/apiv2/fetch_awb/)
请帮助或建议一种方法,我可以使用C#代码获取AWB号码。此外,请检查邮递员和文件说明:
答案 0 :(得分:1)
您可以使用HttpClient
和Newtonsoft.Json轻松完成此工作,因此可能会使用该特定库而不是以form-urlencoded方式发送参数。
using (var client = new HttpClient())
{
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("username", "ecomexpress"),
new KeyValuePair<string, string>("password", "Ke$3c@4oT5m6h#$"),
new KeyValuePair<string, string>("count", "1"),
new KeyValuePair<string, string>("type", "PPD"),
});
var response = await client.PostAsync("http://staging.ecomexpress.in/apiv2/fetch_awb/", content);
var body = await response.Content.ReadAsStringAsync();
var responseObject = JsonConvert.DeserializeObject<ResponseObject>(body);
}
ResponseObject
的位置:
public class ResponseObject
{
[JsonProperty("reference_id")]
public int ReferenceId { get; set; }
[JsonProperty("success")]
public string SuccessText { get; set; }
[JsonIgnore]
public bool Success => SuccessText.Equals("yes", StringComparison.OrdinalIgnoreCase);
[JsonProperty("awb")]
public int[] Awb { get; set; }
}