![](/img/trans.png)
[英]Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https
[英]failed to load "username:password http:// link: Cross origin requests are only supported for protocol schemes http, data, chrome, chrome-extension
我的任务是创建一个Web应用程序,使用户可以添加内容(例如动物或w / e)。 为此,我需要使用一个已构建的API。 问题是每次我尝试获取信息时都会出错。
该代码是用javascript编写的。 并且任务是对API使用GET
, POST
和DELETE
方法。
问题是,当我尝试“发送”请求时,我一直收到“无法加载”错误。 有人可以告诉/告诉我该怎么做吗? 我试图为Chrome "Set --allow-file-access-from-file"
,但没有成功。
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function (){
if (xhr.readyState == 4) {
if (xhr.status == 200) {
console.log(xhr.responseText);
}
if (xhr.status == 404) {
console.log("file is not working bitch");
}
}
}
xhr.open('GET','juraland:28d8d7c89a http://juraland-d887642c13.evalcrew.com/dinosaurs?page[number]=0', true);
xhr.send();
这不是用户名/密码网址的正确格式。 他们应该看起来像
http://username:password@example.com
但是请注意,这是一项非常古老的, 过时的技术,因为它以明文形式发送用户名和密码。 当前浏览器不支持它:
不建议在userinfo字段中使用格式“ user:password”。 除非冒号后的数据为空字符串(表示无密码),否则应用程序不应在userinfo子组件中第一个冒号(“:”)字符之后将任何数据呈现为纯文本。 当作为参考的一部分接收数据时,应用程序可能会选择忽略或拒绝此类数据,并且应拒绝以未加密形式存储此类数据。 事实证明,在几乎每种使用身份验证信息的地方都存在安全隐患。
如果您要连接的服务器依赖于基本身份验证,则可以改为使用RFC7617中定义的方法,该方法代替了原始方案:
要获得授权,客户端
- 从用户那里获取用户名和密码,
- 通过串联用户ID,单个冒号(“:”)字符和密码来构造用户密码,
- 将用户密码编码为一个八位位组序列(有关字符编码方案的讨论,请参见下文),
- 并通过使用Base64([RFC4648],第4节)将该八位位组序列编码为US-ASCII字符序列([RFC0020])来获得基本证书。
...然后在Authentication: Basic
标头中传递该编码字符串,而不是将其作为URL的一部分。
我认为您提到的网址是错误的
“ juraland:28d8d7c89a http://juraland-d887642c13.evalcrew.com/dinosaurs?page[number]=0 ”
“ http://juraland-d887642c13.evalcrew.com/dinosaurs?page[number]=0 ”该URL工作正常。
但是,当我们通过xhr请求发送此消息时,URL转换为
“ https://juraland-d887642c13.evalcrew.com/dinosaurs?page[number]=0 “
那么,您能否以https格式进行api调用?
const xhr = new XMLHttpRequest(); xhr.onreadystatechange = function (){ if (xhr.readyState == 4) { if (xhr.status == 200) { console.log(xhr.responseText); } if (xhr.status == 404) { console.log("file is not working bitch"); } } } xhr.open('GET','http://juraland-d887642c13.evalcrew.com/dinosaurs?page[number]=0', true); xhr.send();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.