jquery Ecom Express API集成

0qx6xfy6  于 2023-03-17  发布在  jQuery
关注(0)|答案(2)|浏览(124)

我尝试在我的项目中集成Ecom Express API。当我使用postman获取AWB编号时,它会给我如下JSON输出:

当我在我的页面上写代码时,我无法得到响应。

<form id="insForm" name="insForm" enctype="multipart/form-data">
<input type="text"id="username" name="username" value="ecomexpress" />
<input type="text" id="password" name="password" value="Ke$3c@4oT5m6h#$" />
<input type="text" id="count" name="count" value="5" />
<input type="text" id="type" name="type" value="cod" />
</form>

function getAWBNo() {
        var formData = new FormData($('#insForm')[0]);
        $.ajax({
            url: 'http://staging.ecomexpress.in/apiv2/fetch_awb/',
            type: 'POST',
            data: formData,
            dataType: 'json',
            cache: true,
            contentType: "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
            processData: false,
            type: 'POST',
            success: function (data) {
            }
        });
    }

我用的是Razor v3。

eoigrqb6

eoigrqb61#

谢谢大家。我已经通过使用NuGet包中可用的Rest API解决了我的问题。

4ktjp1zp

4ktjp1zp2#

public async Task<JsonResult> FetchAWB()
    {
        var options = new RestClientOptions("https://clbeta.ecomexpress.in")
        {
            MaxTimeout = -1,
        };
        var client = new RestClient(options);
        var request = new RestRequest("https://api.ecomexpress.in/apiv2/fetch_awb/", Method.Post);
        request.AddHeader("Authorization", "Basic QU5NT0xDT1VSSUVSU0VSVklDRVMyMTE2NjM6N1ZFaFpHcU11OA==");
        request.AlwaysMultipartFormData = true;
        request.AddParameter("username", "******************");
        request.AddParameter("password", "*********");
        request.AddParameter("count", "1");
        request.AddParameter("type", "PPD");
        RestResponse response = await client.ExecuteAsync(request);
       if( response.IsSuccessStatusCode==true)
        {
            FetchAWBModel rcat = JsonConvert.DeserializeObject<FetchAWBModel>(response.Content);
            var pm = rcat.awb;

            return Json(rcat.awb);
        }
        else
        {
            return Json(response.Content);
        } 
    }

相关问题