무기명 토큰이 필요한 서버로 ionic2 프로젝트의 게시물 요청을하려고합니다.이온 2 (각도 2)의 무기 토큰으로 게시물 요청
var headers = new Headers();
headers.append('Authorization', 'Bearer '+mytoken);
let options = new RequestOptions({ headers: headers });
let body = [
{key: 'vid', value: myvid},
{key: 'start_time', value: date.toISOString()}
].map(x => `${encodeURI(x.key)}=${encodeURI(x.value)}`).join('&');
return this.http.post(mybasisurl, body, options)
.map((res: Response) => res.json())
.toPromise();
하지만 전혀 작동하지 않습니다. 좀 더 구체적으로 400 (잘못된 요청) 얻을 :
{"_body":"{\"success\":false,\"description\":\"vid not set\",\"error\":601}","status":400,"ok":false,"statusText":"Bad Request","headers":{"content-type":["application/json"]},"type":2,"url":"myurl"}
나는 토큰 소지자없이 정상적인 POST 요청에서 비슷한 것을 사용하고 올바르게 일하는 :
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
let options = new RequestOptions({ headers: headers });
let body = [
{key: 'email', value: email},
{key: 'password', value: password}
].map(x => `${encodeURI(x.key)}=${encodeURI(x.value)}`).join('&');
return this.http.post(myurl, body, options)
.retry(NUM_HTTP_RETRIES)
.map((res: Response) => res.json())
.toPromise();
어떤 제안?
게시하는 대신 Martin의 답변을 표시해야합니다. – Sajeetharan