javascript - 使用参数发送凭据 - PUT -Firefox
问题描述
我登录了沃尔玛的网站,我有一个购物车。当我将商品添加到购物车时,我会提出PUT
请求
PUT 请求图片 - https://i.imgur.com/f9lWqbC.png
就这样,我将一个项目添加到我的购物车。
现在,进入这篇文章的重点。我正在为 Firefox 编写扩展程序,主要的是content_script
. 脚本的主要功能是发出与单击沃尔玛页面上的按钮相同的请求Add to cart
,但我不知道如何发送可以在请求标头中找到的所有凭据。
显然,我有权发送正确的请求,但这只能通过单击按钮,我的目标是通过content_script
(或后台脚本)与我的扩展一起发送它。
content_script.js
(function(){
var params = {"cartItems":[{"offerId":"8E5AE39B44CD467DAC4AAA3A0042110F","quantity":3}]}
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// Typical action to be performed when the document is ready:
var res = JSON.parse(xhttp.responseText);
console.log(res);
}
};
xhttp.open("PUT", "https://grocery.walmart.com/api/v3/cart/:GCRT/items", true);
xhttp.withCredentials = true;
xhttp.setRequestHeader("Content-Type", "application/json; charset=utf-8");
xhttp.send(JSON.stringify(params));
})();
如您所见,我已xhttp.withCredentials
设置为,true
但这不起作用,因为我的控制台上没有任何内容。
正确的问题是:如何向沃尔玛证明这个请求仍然来自我的电脑和我的帐户?
解决方案
尝试发送该图片中包含的更多标头,但我认为您仍然不能发送cookie
键值对,因为XMLHttpRequest
.
推荐阅读
- wpf - 使用 ScrollViewer 加载 2 个 DataGrids + StackPanel 时间太长,替代方案?
- windows - RemoteApp Web 客户端:命令行参数
- json - 数据库模型自定义 JSONField 值在测试用例之间持续存在
- flutter - 如何在 Flutter 中浏览 PageView?
- hyperledger-fabric - 我们可以更新关系的价值吗
- javascript - 如何在 JSBin 中进行 lodash 导入?
- javascript - Dropdown onChanged 不解散的问题
- c++ - 使用 Cstrings 进行猪拉丁语转换
- excel - 查找并替换每次出现的多个值(VBA)
- java - 谁消耗更多内存,ArrayList 还是 HashSet / LinkedHashSet?