简体   繁体   English

为什么我在向 Instagram 发送发布请求时收到错误 403?

[英]Why am I getting an error 403 while sending a post request to Instagram?

I want to unfollow specific user on instagram by using a request to endpoint, for which I have used fiddler to find.我想通过使用对端点的请求来取消关注 instagram 上的特定用户,为此我使用了 fiddler 来查找。 But I'm getting an 403 error and nothing happends.但是我收到 403 错误,但什么也没发生。 I'm a newbie at this.我是这方面的新手。

Here is the code:这是代码:

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);

Is there any technical aspect that I'm missing?有没有我遗漏的技术方面?

EDIT 1: I'm sending it from chrome console while logged to my instagram account.编辑 1:我在登录到我的 instagram 帐户时从 chrome 控制台发送它。

Yes you are missing few things.是的,您缺少一些东西。

Authentication验证

When you're browsing Instagram as usual, browser will add headers to each request.当您像往常一样浏览 Instagram 时,浏览器会为每个请求添加标头。 What's more important that headers contain cookies and origin.更重要的是,标题包含 cookies 和来源。 By executing the code you listed headers (or any other authentication data) is not added.通过执行代码,您列出的标头(或任何其他身份验证数据)不会被添加。

Other security checks其他安全检查

I guess Instagram checks origin of received requests.我猜 Instagram 会检查收到的请求的来源。 It may not be possible to execute it this way - ie.可能无法以这种方式执行它 - 即。 manually executing JS code.手动执行 JS 代码。

Possible solution - use API provided by Instagram.可能的解决方案 - 使用 Instagram 提供的 API。 For more details please refer to documentation: https://www.instagram.com/developer/更多详情请参考文档: https://www.instagram.com/developer/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM