简体   繁体   English

XMLHttpRequest | 手动发送请求让我得到 2111 个字符的响应,但使用 XMLHttpRequest 响应的长度为 179

[英]XMLHttpRequest | Sending a request by hand gets me a response of 2111 characters but using XMLHttpRequest the response has a lenght of 179

I basically copy-pasted the MDN code, and I triple checked the URL.我基本上是复制粘贴了 MDN 代码,并且对 URL 进行了三次检查。 I can't find the reason as to why the responses differ.我找不到响应不同的原因。 For reference, here is my code: Edit: Didn't see cookies got sent, I'm sorry作为参考,这是我的代码:编辑:没有看到 cookie 被发送,我很抱歉

 function getUsernames(str) { console.log(str) } function reqListener() { alert(getUsernames(this.responseText)); } var oReq = new XMLHttpRequest(); oReq.addEventListener("load", reqListener); oReq.open("GET", "https://www.instagram.com/graphql/query/?query_hash=c76146de99bb02f6415203be841dd25a&variables=%7B%22id%22%3A%2217199917378%22%2C%22include_reel%22%3Atrue%2C%22fetch_mutual%22%3Atrue%2C%22first%22%3A24%7D"); oReq.responseType = "arraybuffer"; oReq.send(); oReq.onload = function(e) { var arraybuffer = oReq.response; // not responseText console.log(arraybuffer) /* ... */ }

Seems the xmlhttprequest is truncated and does not contain the data you want unless you have key (auth)似乎 xmlhttprequest 被截断并且不包含您想要的数据,除非您有密钥(身份验证)

Here is something hacky: How can I get a user's media from Instagram without authenticating as a user?这里有一些 hacky: 如何在不进行用户身份验证的情况下从 Instagram 获取用户的媒体?

You also have two load handlers.您还有两个负载处理程序。 You likely mean this你可能是这个意思

 function getUsernames(str) { return JSON.parse(str); // of course do something with this when complete } function reqListener() { console.log(getUsernames(this.responseText)); } var oReq = new XMLHttpRequest(); oReq.addEventListener("load", reqListener); oReq.open("GET", "https://www.instagram.com/graphql/query/?query_hash=c76146de99bb02f6415203be841dd25a&variables=%7B%22id%22%3A%2217199917378%22%2C%22include_reel%22%3Atrue%2C%22fetch_mutual%22%3Atrue%2C%22first%22%3A24%7D"); oReq.responseType = "text"; oReq.send();

Okay, so I just found out that in the headers cookies got send.好的,所以我刚刚发现在标题中发送了 cookie。 After clearing my cookies, I got the same result as the program.清除我的 cookie 后,我得到了与程序相同的结果。 I thank you all for your participation!我感谢大家的参与!

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

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