처음으로 여기에 묻습니다.Axios 기본 승인이 Reactjs를 통과하지 못함
일부 승인이 필요한 팀이 만든 폭풍우 앱에 대한 GET 호출을하려고합니다. 우체부를 사용하는 경우 테스트하고 일부 구성 후에는 모든 컬이
curl --verbose --user ID:SECRET -H "Accept: application/json" https://api.stormpath.com/v1/tenants/current
...
< HTTP/1.1 302
< Cache-Control: private, no-cache, no-store, max-age=0, no-transform
< Date: Tue, 10 Jan 2017 09:27:14 GMT
< Location: https://api.stormpath.com/v1/tenants/TENANTID
< Pragma: no-cache
< Stormpath-Request-Id: f8e4dee0-d716-11e6-9795-22000aa92aa2
< Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
< X-Frame-Options: SAMEORIGIN
< Content-Length: 0
< Connection: keep-alive
<
* Connection #0 to host api.stormpath.com left intact
을했다 사용하여 200
Results of API call in Postman
했다하지만 React
에 Axios
을 통해 전화를 걸하려고 할 때 나는 401를 얻을 수 있습니다 오류.
XMLHttpRequest cannot load https://api.stormpath.com/v1/tenants/current. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 401.
이 내가 사용하는 것입니다 :
axios({
method: 'get',
url: "https://api.stormpath.com/v1/tenants/current",
auth:
{
username: 'api ID',
password: 'api Secret'
}
})
나는 이유를 알고하지 않습니다하지만 내가 가진 응답에 따라 사용자 이름과 암호를 제공 아니에요.
비슷한 질문이 있지만 아직 답변이 없습니다. 이를 읽어 주셔서
감사의
Cannot Basic Auth from React App with Axios or SuperAgent
Reactjs Axios/Spring boot security
.
아마 잘못된 API 키/암호입니다. 오류가 발생했기 때문일 수 있습니다. –
API 키/비밀은 Postman을 사용하여 올바르게 작동합니다. 나는 주소 표시 줄을 통해 API에 액세스하기 위해 API 키/암호를 사용하기까지했으며 여전히 작동했습니다. –