简体   繁体   English

如何在jQuery发布请求中发送api_key和api_secret参数

[英]how to send api_key and api_secret arguments in jquery post request

$.ajax({
        type: 'POST',
        url: 'http://apius.faceplusplus.com/detection/detect',
        crossDomain: true,
        cache: false,
        async: true,
        data: '{ "comment" }',
        dataType: 'jsonp',
        success: function(responseData) {
           alert(JSON.stringify(responseData));
        },
        error: function (responseData, textStatus, errorThrown) {
            alert(JSON.stringify(responseData));
        }
    });

I am sending a post request to above which requires api_key and api_secret parameters for authentication. 我向上面发送了一个发布请求,该请求需要使用api_keyapi_secret参数进行身份验证。 I tried sending value of this 2 paramenters like this in above request: 我在上面的请求中尝试发送这2个参数的值:

headers: 
{
    "Authorization": "Basic " + Base64.encode('value of api key here' + ":" + 'value of api secret here') 
},

But when I execute the request it says 400 BAD REQUEST and when I hit the url in browser it shows 但是,当我执行请求时,它说400 BAD REQUEST,当我在浏览器中点击URL时,它显示

{ "error": "MISSING_ARGUMENTS: api_key", "error_code": 1004 } {“ error”:“ MISSING_ARGUMENTS:api_key”,“ error_code”:1004}

Please suggest me a solution. 请给我建议一个解决方案。 I am stuck for long time. 我被困了很长时间。

在ajax请求的数据对象中传递键/值对,如下所示:

data: '{ "api_key": "thekeyhere", "api_secret": "thesecrethere" }'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM