首页 > 解决方案 > 使用参数发送凭据 - 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但这不起作用,因为我的控制台上没有任何内容。

正确的问题是:如何向沃尔玛证明这个请求仍然来自我的电脑和我的帐户?

标签: javascriptxmlhttprequestfirefox-addon-webextensions

解决方案


尝试发送该图片中包含的更多标头,但我认为您仍然不能发送cookie键值对,因为XMLHttpRequest.


推荐阅读