因此,我无法获取此http请求对象以及请求发送我的标头。
loginUser(email,password){
console.log("loginuser");
let formData:FormData = new FormData();
formData.append("format","json");
formData.append("email",email);
formData.append("password",password);
let headers = new HttpHeaders();
headers.append('command', 'ProcessLoginPos');
headers.append('Access-Control-Allow-Origin', '*');
const req = new HttpRequest('POST', 'http://localhost:8080/ProjectOne/', formData, { 'headers':headers, reportProgress: true, responseType: 'text' });
return this.http.request(req,{},{"command": "ProcessLoginPos"});
}
答案 0 :(得分:0)
您的最后一行应遵循以下模式:
return this.http.post(url, body, { headers: headers, params: params })
最后你应该得到类似的东西:
return this.http.post('http://localhost:8080/ProjectOne/', formData, { headers: headers })
结果(但我不知道,你为什么需要new FormData()
):
loginUser(email, password) {
let formData: FormData = new FormData();
formData.append("format", "json");
formData.append("email", email);
formData.append("password", password);
let headers = new HttpHeaders();
headers.append('command', 'ProcessLoginPos');
headers.append('Access-Control-Allow-Origin', '*');
return this.http.post('http://localhost:8080/ProjectOne/', formData, { headers: headers })
}