![](/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.