react를 사용하여 C# WebAPI 인증 토큰을 얻으려고 애 쓰고 있습니다. 올바르게 작동하는 우편 배달부 요청이 있습니다. 그것은 예상대로 나에게 내 토큰을 제공합니다 : 나는 Axios의 및 가져 오기 모두 사용이 요청을 다시 시도Axios에 반응하여 POST 메서드가 C# WebAPI 토큰 요청과 작동하지 않음
.
Attempt 1:
fetch('http://localhost:56765/token', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: JSON.stringify({ username: '[email protected]', password: 'Test123!', grant_type: 'password' })
})
Attempt 2:
axios('http://localhost:56765/token', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: JSON.stringify({ username: '[email protected]', password: 'Test123!', grant_type: 'password' })
})
Attempt 3:
const data = JSON.stringify({ username: '[email protected]', password: 'Test123!', grant_type: 'password' });
const headers = { 'Content-Type': 'application/x-www-form-urlencoded', };
axios.post('http://localhost:56765/token', data, { headers })
내가 요청을 할 때, 응답은 다음과 같습니다 :
400 Bad Request
{"error":"unsupported_grant_type"}
사람이 알고 있나요 다음과 같이 요청했다?
편집 :
나 다음 qs
를 설치 한 근무 코드 :
var qs = require('qs');
const data = qs.stringify({ username: '[email protected]', password: 'Test123!', grant_type: 'password' });
axios.post('http://localhost:56765/token', data)
내가 완전히 헤더를 생략 할 수 있었다.
크리스마스 날에 답해 주신 Brub에게 많은 감사를드립니다!
은이 디버깅을 시도 되세요 서버쪽에? – stone