在 httprequest 上写入请求负载 属性
Writing Request Payload property on httprequest
我正在尝试开发一个浏览器扩展程序,以帮助人们更轻松地处理某些事情。
我需要做的一件事是发送几个 http 请求。
我需要重新创建站点在执行某些操作时发出的请求。
现在站点使用Request Payload,这是我第一次使用(使用表单数据),因此我不知道如何使Request Payload与站点发送请求时相同。
var request = new XMLHttpRequest(),
url = 'https://www.hidden.com/api/v1/tipuser/',
data = 'steam_64=76561198364912967&tip_asset_ids=[]&tip_balance=0',
token ='...';
request.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log("The request and response was successful!");
}
};
request.open('POST', url, true);
request.setRequestHeader('Content-type', 'text/plain');
request.setRequestHeader('authorization', token);
request.send(data);
这是我的代码,发送后您可以看到我的请求负载的外观。
几天来我一直遇到困难,我在网上搜索但找不到 this.I 的解决方案知道我只需要以不同的方式编写它。
This is site's request
This is my request
干杯!
您能否尝试将您的请求发送为 application/json 并像下面的示例那样构建您的数据 object?
您的Content-type请求header应该是application/json
var request = new XMLHttpRequest(),
url = 'https://jsonplaceholder.typicode.com/posts/',
data = {
steam_64: '76561198364912967',
tip_asset_ids: [],
tip_balance: 0,
token: '',
};
request.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log("The request and response was successful!");
}
};
request.open('POST', url, true);
request.setRequestHeader('Content-type', 'application/json');
request.setRequestHeader('authorization', data.token);
request.send(JSON.stringify(data));
我正在尝试开发一个浏览器扩展程序,以帮助人们更轻松地处理某些事情。 我需要做的一件事是发送几个 http 请求。
我需要重新创建站点在执行某些操作时发出的请求。 现在站点使用Request Payload,这是我第一次使用(使用表单数据),因此我不知道如何使Request Payload与站点发送请求时相同。
var request = new XMLHttpRequest(),
url = 'https://www.hidden.com/api/v1/tipuser/',
data = 'steam_64=76561198364912967&tip_asset_ids=[]&tip_balance=0',
token ='...';
request.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log("The request and response was successful!");
}
};
request.open('POST', url, true);
request.setRequestHeader('Content-type', 'text/plain');
request.setRequestHeader('authorization', token);
request.send(data);
这是我的代码,发送后您可以看到我的请求负载的外观。 几天来我一直遇到困难,我在网上搜索但找不到 this.I 的解决方案知道我只需要以不同的方式编写它。
This is site's request
This is my request
干杯!
您能否尝试将您的请求发送为 application/json 并像下面的示例那样构建您的数据 object?
您的Content-type请求header应该是application/json
var request = new XMLHttpRequest(),
url = 'https://jsonplaceholder.typicode.com/posts/',
data = {
steam_64: '76561198364912967',
tip_asset_ids: [],
tip_balance: 0,
token: '',
};
request.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log("The request and response was successful!");
}
};
request.open('POST', url, true);
request.setRequestHeader('Content-type', 'application/json');
request.setRequestHeader('authorization', data.token);
request.send(JSON.stringify(data));