我正在尝试通过邮寄方式从后端获取数据。我正在尝试以下操作,但出现错误不起作用。
有人纠正我的发帖请求吗?
import { Injectable } from '@angular/core';
import { Http, Response, RequestOptions, Headers } from '@angular/http';
@Injectable()
export class ServerService {
constructor(private http:Http) { }
headers = new Headers();
headers.append('Content-Type', 'application/json');
postParam = {
"clientId": "RETAIL",
"spvParam": {
"productCode": "PDO",
"consigneeCountry": "MY",
"salesOrgRef": "TH61",
"salesOrgFacilityCode": "THBKK1",
"salesOrgChnl": "eCommerce",
"pickUpAcctRef": "5999999108",
"facilityId": "MYKUL1"
}
}
options = new RequestOptions({ headers: this.headers, body:this.postParam });
getDataByPost(){
alert('starts');
let url = `http://mykullstc004004.apis.dhl.com:8003/efoms/getServiceProductV2`;
this.http.post(url, {}, this.options ).subscribe(res => console.log( 'res', res ));
}
}
更新
import { Component, OnInit } from '@angular/core';
import { ServerService } from './shared/service/server.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
constructor(private server:ServerService){}
ngOnInit(){
this.server.getDataByPost();
}
}