这是我运行Ionic Serve
时得到的结果。我使用的是ionic4版本的Angular 8。
sendPostRequest() {
let headers = new HttpHeaders();
headers.append("Accept", 'application/json');
headers.append('Content-Type', 'text/plain');
let options = {
headers: headers
}
/*
if (this.authService.checkAuth()) {
const token = 'something';
headers = headers.set('Authorization', `Bearer ${token}`);
}
const authReq = req.clone({ headers });*/
let postData = {
"username": "Customer004",
"email": "customer004@email.com",
"password": "0000252525",
"gender": "male",
}
/*this.http.post("http://localhost/android/Api.php?apicall=signup", postData, requestOptions)
.subscribe(data => {
console.log(data['_body']);
}, error => {
console.log(error);
});*/
var options = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
};
this.http.post("http://localhost/android/Api.php?apicall=signup", postData, options)
.subscribe(data => {
console.log(data);
});
}
{
"name": "registration",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "https://ionicframework.com/",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/common": "~8.1.2",
"@angular/core": "~8.1.2",
"@angular/forms": "~8.1.2",
"@angular/http": "^7.2.16",
"@angular/platform-browser": "~8.1.2",
"@angular/platform-browser-dynamic": "~8.1.2",
"@angular/router": "~8.1.2",
"@ionic-native/core": "^5.0.0",
"@ionic-native/splash-screen": "^5.0.0",
"@ionic-native/status-bar": "^5.0.0",
"@ionic/angular": "^4.7.1",
"core-js": "^2.5.4",
"rxjs": "~6.5.1",
"tslib": "^1.9.0",
"zone.js": "~0.9.1"
},
"devDependencies": {
"@angular-devkit/architect": "~0.801.2",
"@angular-devkit/build-angular": "~0.801.2",
"@angular-devkit/core": "~8.1.2",
"@angular-devkit/schematics": "~8.1.2",
"@angular/cli": "~8.1.2",
"@angular/compiler": "~8.1.2",
"@angular/compiler-cli": "~8.1.2",
"@angular/language-service": "~8.1.2",
"@ionic/angular-toolkit": "^2.1.1",
"@types/jasmine": "~3.3.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "^8.9.5",
"codelyzer": "^5.0.0",
"jasmine-core": "~3.4.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.1.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.15.0",
"typescript": "~3.4.3"
},
"description": "An Ionic project"
}
您应该进行导入:从'@angull/Http'导入{Http,Headers,RequestOptions};
。
来自http的DI注入是可以的。然后简单地使用RequestOptions
,如下所示:
sendPostRequest() {
let headers = new Headers({'Content-Type': 'application/json'});
// headers.append('Content-Type', 'text/plain');
// I didn't understand if you need this append.
let options = new RequestOptions({ headers: headers });
const postData = {
"username": "Customer004",
"email": "customer004@email.com",
"password": "0000252525",
"gender": "male",
}
this.http.post("http://localhost/android/Api.php?apicall=signup", postData, options)
.subscribe(data => {
console.log(data);
});
}
很好的一天。我不熟悉使用VSCode键入脚本。 获取以下错误: > 错误TS2322:类型'()= 代码: DTO。输电系统 LinkedObject.ts 我正在尝试使用上述接口方法实例化类: TravelClientFormPopulator.ts 任何帮助都将不胜感激。
我刚刚更新到Dart2和Flatter sdk:' 无法将参数类型“Object”指定给参数类型“ImageProvider”。), 我只是从弗利特开始,不知道该去哪里找别的。
由于最近的更新,我正面临这个问题,请伙计们帮帮我
我试图用flutter插件HTTP发出HTTP POST请求,但我得到了一个标题错误。有人知道这是什么原因吗?因为在我的其他应用程序中,这工作得非常好?
我试图制作一个简单的饼图,但在工厂构造函数中使用未来的数据时遇到了问题。错误信息显示: 预期有2个位置参数,但找到1个。 参数类型“未来” 以下是代码: 编辑:我能够使用Future Builder修复此问题。我的代码更改:
我正在构建一个nativescript应用程序,并在tns构建Android时得到这些错误: src/app/services/cabin.service.ts(21,86):错误TS2345:类型为“Object”的参数不能分配给类型为“Response”的参数。“Object”类型可分配给极少数其他类型。您的意思是使用“any”类型来代替吗?类型“Object”中缺少属性“type”。src/