첫 크롬 확장을 구현하는 데 어려움이 있습니다. JavaScript와 HTTP를 사용하는 데 많은 경험이 없으므로 이해가되지 않으면 용서해주십시오. 크롬 확장 인증
크롬 확장
는 here을 발견하고 세 개의 파일을 포함 할 수 있습니다addratings.js
,
icon.png
및
manifest.json
을.
addratings.js
var http = new window.XMLHttpRequest();
http.onreadystatechange = function(data) {
if (http.readyState == 4) {
alert(JSON.stringify(http));
}
}
var url = "http://myanimelist.net/api/anime/search.xml?q=Madoka";
http.open('GET', url, true);
http.send();
manifest.json
파일은 다음과 같습니다 : 나는 (this page에 갈 때가 트리거) HTTP 응답을 스크립트를 실행하면
{
"name": "Anime Ratings",
"version": "1.0",
"description": "Shows anime ratings next to anime titles in a Web page.",
"permissions": [
"cookies",
"http://myanimelist.net/*"
],
"content_scripts": [ {
"matches": ["http://en.wikipedia.org/wiki/Category:Anime_of_2011"],
"run_at": "document_end",
"js": ["addratings.js"]
} ]
}
내가받을 다음과 같이 표시됩니다.
{"statusText":"Unauthorized","responseText":"Invalid credentials","response":"Invalid credentials","onabort":null,"readyState":4,"upload":{"onloadstart":null,"onabort":null,"onerror":null,"onload":null,"onprogress":null},"onerror":null,"status":401,"responseXML":null,"onprogress":null,"onload":null,"withCredentials":false,"onloadstart":null,"responseType":""}
Wireshark로 HTTP 요청을 캡처하고 '인증'HTTP 헤더가 누락되었음을 확인했습니다. 어떤 오류 메시지가 설명되어 있습니다.
그러나 this tutorial을 읽은 후 manifest.json 파일에 도메인을 추가했기 때문에 인증 헤더가 요청에 포함되어 있어야한다는식이 었습니다.
그래서이 http 요청에 인증 헤더를 어떻게 제공합니까?