0
ここで間違っていることがわかりません。コードはかなり簡単です。角度4 HttpClientがパラメータまたはヘッダーを設定していない
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs/Rx';
@Injectable()
export class Service {
private baseUrl = 'http://localhost:8443';
constructor(private http: HttpClient) { }
callSecurityGateway(): Observable<String> {
const params = new HttpParams()
.set('grant_type', 'password')
.set('scope', 'read')
.set('username', 'myusername')
.set('password', 'mypassword');
const headers = new HttpHeaders().set('Authorization', 'Basic s89s89s89asd');
const httpOptions = {
headers: headers,
params: params,
responseType: 'text',
// withCredentials: true
};
// this works to ram the parameters in
// const oauthUrl = '/oauth/token?grant_type=password&scope=read&username=myusername&password=mypassword';
// return this.http.post<String>(this.baseUrl + oauthUrl, httpOptions);
return this.http.post<String>(this.baseUrl + '/oauth/token', httpOptions);
}
}
私がリクエストヘッダに表示することはこれです:
OPTIONS /oauth/token HTTP/1.1
Host: localhost:8443
Connection: keep-alive
Access-Control-Request-Method: POST
Origin: http://localhost:4200
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/62.0.3202.89 Safari/537.36
Access-Control-Request-Headers: content-type
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
私もそこのような任意のパラメータがなければなりません表示されません。
このことができますが、私はコンソールにhttpOptions
オブジェクトで参照することは私に私が設定した4つのparamsの配列ですheaders.lazyUpdate
のヘッダとparams.updates
内のparamsを示している場合、私は知りません。
例がなくなりました。逆方向に進むほうが簡単かもしれないと考えて、httpclient
の代わりにhttp
を使用してください。
、:あなたは、サーバー側で
Access-Control-Allow-Credentials: true
を持っているクロスサイト上の資格情報の仕事をするためにこのコードを追加してみていない場合や、クッキーなどの資格情報が送信されません。 、 –