【问题标题】:Why am I getting an error 403 while sending a post request to Instagram?为什么我在向 Instagram 发送发布请求时收到错误 403?
【发布时间】:2019-11-09 08:59:05
【问题描述】:

我想通过使用对端点的请求来取消关注 instagram 上的特定用户,为此我使用了 fiddler 来查找。 但是我收到 403 错误,但什么也没发生。我是这方面的新手。

代码如下:

var http = new XMLHttpRequest();
var url = 'https://www.instagram.com/web/friendships/8752655712/unfollow/';
var params = 'orem=ipsum&name=binny';
http.open('POST', url, true);

//Send the proper header information along with the request
http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');

http.onreadystatechange = function() {//Call a function when the state changes.
    if(http.readyState == 4 && http.status == 200) {
        alert(http.responseText);
    }
}
http.send(params);

我是否缺少任何技术方面的内容?

编辑 1:我在登录到我的 instagram 帐户时从 chrome 控制台发送它。

【问题讨论】:

    标签: javascript http post request xmlhttprequest


    【解决方案1】:

    是的,您缺少一些东西。

    身份验证

    当您像往常一样浏览 Instagram 时,浏览器会为每个请求添加标头。更重要的是标头包含 cookie 和来源。通过执行代码,您列出的标头(或任何其他身份验证数据)不会被添加。

    其他安全检查

    我猜 Instagram 会检查收到请求的来源。可能无法以这种方式执行它 - 即。手动执行JS代码。

    可能的解决方案 - 使用 Instagram 提供的 API。更多详情请参考文档:https://www.instagram.com/developer/

    【讨论】:

    • 感谢您的回答。由于他们的 api 没用,它不支持取消关注的用户,有没有办法手动将我从 Fiddler 获得的标头添加到我的请求中?对于来源检查,我一直在使用请求来获取关注者和取消关注者的列表,因此情况可能并非如此。
    • 有一种方法可以将标头添加到 XMLHttpRequest (http.setRequestHeader) 中,但它不允许您添加 Cookie 标头。
    • 我登录后chrome控制台不提供cookies吗?
    • 尝试在.send()之前添加http.withCredentials = true;
    • 还是一样。我有一个包含 10 行文本的头文件。我怎样才能将它与我的请求一起添加?
    猜你喜欢
    • 2015-12-04
    • 1970-01-01
    • 1970-01-01
    • 2015-11-21
    • 2020-04-28
    • 2013-01-26
    • 2019-10-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多