我正在使用ionic2和rest API。
这是我的代码
byte
但是身体值传递给了一个对象。
如何解决此问题。
这是我的输出。
let body={
O_NUMBER: "",
CART_ID: "",
S_ID: "",
PRODUCTS:"",
BILLING: "string",
SHIPPING: "",
PAYMENT: {
"TYPE": "",
"SUBTOTAL": "",
"TAX_TOTAL": "",
"TOTAL_AMOUNT": "",
"TRANSACTION_ID": ""
},
DATE: "",
STATUS: "",
customerId: ""
}
let headers = new Headers();
headers.append('Content-Type','application/json');
let options = new RequestOptions({
method: "POST",
body: body,
headers: headers });
return this.http.get(this.url + 'orders?access_token='+ this.Id+body,options);
我也试过http.post。
但不行。
答案 0 :(得分:0)
要将值作为查询字符串的一部分传递,请使用URLSearchParams
中的@angular/http
类:
import { Headers, URLSearchParams } from '@angular/http'
let body = { ... };
let queryParams = new URLSearchParams();
// Add AccessToken to query parameters.
queryParams.set('access_token', this.Id);
// Add all the elements of the 'body' object to query parameters.
for (let key in body) {
if (body.hasOwnProperty(key)) {
queryParams.set(key, body[key]);
}
}
let headers = new Headers();
headers.append('Content-Type','application/json');
let options = new RequestOptions({
method: 'GET',
headers: headers,
params: queryParams
});
return this.http.get(this.url + 'orders', options);