的实际结果响应
我正在使用 @ionic-native/http在我的离子4项目中使用userId和password and theader和'content-type'来登录用户:'application/json'通过邮政方法。它在Android和iOS上正常工作,但它以HTTP 400错误响应。
Dependencies:
"@ionic-native/http": "^5.3.0",
"cordova-plugin-advanced-http": "^2.0.9",
我使用 @angular/http感到疲倦,但它在浏览器,Android和iOS上给出了CORS错误。而且我无法更改服务器端代码以启用CORS。
代码:
import { HTTP } from '@ionic-native/http/ngx';
// Login method
async login(userId, password) {
// login user
const httpBody = {
'UserId': userId,
'Password': btoa(password)
};
const httpHeader = {
'Content-Type': 'application/json',
};
const user = await this.http.post(this.loginURL, httpBody, httpHeader);
return JSON.parse(user.data);
}
与状态密码200
的预期结果响应使用状态代码400
我有相同的问题;在我的情况下,我通过将数据序列化器设置为'utf8',并通过将Content-Type标头设置为'应用程序/x-www-form-urlenCoded'
this.http.setDataSerializer('utf8');
const httpHeader = {
'Content-Type': 'application/application/x-www-form-urlencoded'
};