使用Jquery AJAX的POST标头和正文

You*_*uss 2 javascript ajax jquery post header

我必须将POST发送到包含标头和正文的代理API:

Action  POST https://demo-api.ig.com/gateway/deal/session

Header  
Content-Type: application/json; charset=UTF-8
Accept: application/json; charset=UTF-8
X-IG-API-KEY: 5FA056D2706634F2B7C6FC66FE17517B

Body    
{ 
"identifier": "A12345", 
"password": "112233" 
} 
Run Code Online (Sandbox Code Playgroud)

该API位于此处:https//labs.ig.com/rest-trading-api-guide

问题是互联网上的每个示例都将数据作为“数据”发送,如下所示:

jQuery.ajax(

{

url : 'https://demo-api.ig.com/gateway/deal/session',

type: 'POST',

dataType : "json",

data: {identifier: "A12345", password: "112233"}

});
Run Code Online (Sandbox Code Playgroud)

我不明白,标题和正文在哪里?所有示例基本上都像这样,我无法对此一目了然。

Saa*_*aar 5

数据用于您所用的post参数,标题具有其自己的对象。

jQuery.ajax(

{

url : 'https://demo-api.ig.com/gateway/deal/session',

type: 'POST',

dataType : "json",

headers: {"X-IG-API-KEY":"5FA056D2706634F2B7C6FC66FE17517B"},

data: {identifier: "A12345", password: "112233"}

});
Run Code Online (Sandbox Code Playgroud)