当我向网站服务发送发布请求时,它可以在浏览器上运行,但在Android移动设备上却显示错误,例如状态为0:URL为null 请帮我解决这个问题。
我的service.ts
Login.ts
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Http, Response, Headers } from '@angular/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import 'rxjs/add/observable/throw';
@Injectable()
export class RestProvider {
constructor(public httpClient : HttpClient, public http: Http) {
console.log('Hello RestProvider Provider');
}
getlogindetails(credentials) {
let apiUrl = 'http://example.com/data/service.php?Method=';
let headers = new HttpHeaders();
headers.append('Content-Type', 'application/json');
return this.http.post(apiUrl+'Login', JSON.stringify(credentials))
.map((res: Response) => res.json());
}
}
import { HttpModule } from '@angular/http';
import { HttpClientModule } from '@angular/common/http';
imports: [
HttpClientModule,
HttpModule
IonicModule.forRoot(MyApp)
],
providers: [
RestProvider
]
export class AppModule {}
Login.ts文件
import { RestProvider } from '../../providers/rest/rest';
import { HttpClient } from '@angular/common/http';
constructor(public loadingCtrl: LoadingController, public navCtrl: NavController, public navParams: NavParams, public modalCtrl: ModalController, public toastCtrl: ToastController, public restProvider: RestProvider, private http: HttpClient, public menu: MenuController) {
}
verifylogin() {
this.restProvider.getlogindetails(this.loginData).subscribe((result)=>{
console.log("result:"+result);
}, (err) => {
//this.loading.dismiss();
alert("err:"+err);
this.presentToast(err);
});
}
以上代码在浏览器上有效,但在android设备上无效。请帮我解决这个问题。