我的问题很简单,但我找不到解决方案。我需要发布一个这样的身体: - key:用户名值:moi - key:paswd值:root -... 它适用于邮递员,但是当我尝试使用角度5时,我没有回应:
readonly ROOT_URL = 'localhost:8080/auth/';
getToken() {
const data: Post = {
username: 'root',
passwords: 'root',
grant_type: 'password',
client_id: 'admin-cli'
}
this.token = this.http.post(this.ROOT_URL,data, headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded'));
}
当我在Postman中发布查询时,我收到一个令牌,我需要存储它。
答案 0 :(得分:0)
Angular <video width="100%" height="100%" autoplay="1" poster="/test6.jpg">
<source src="/VideoHeader2.0.webm" type="video/webm">
</video>
请求不返回数据,它返回数据的 observable 。在observable上使用http.post
来获取数据。
subscribe
答案 1 :(得分:0)
/**
* Interface to be implemented by an Activity hosting MainFragments. Via this interface, the hosting
* activity always has a reference to the Fragment currently being displayed (state "started") in the
* main fragment container.
*
* Created by kazume on 05.02.2017.
*/
public interface OnFragmentSelectedListener {
void setSelectedFragment(MainFragment fragment);
}
但是我没有像邮差那样收到令牌
readonly ROOT_URL = 'localhost:8080/auth/realms/demo/protocol/openid-connect/token';
posts : any;
constructor(private http: HttpClient) {}
getToken() {
const data: Post = {
username: 'root',
passwords: 'root',
grant_type: 'password',
client_id: 'admin-cli'
}
this.http.post(this.ROOT_URL,data, {headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')}).subscribe(data => this.token = data)}
}
}