Request Payload and Anuglar post
Reference:
How to send right format of payload in Angular 2 since the php backend accept only 'x-www-form-urlencoded'? http://stackoverflow.com/questions/38375791/how-to-send-right-format-of-payload-in-angular-2-since-the-php-backend-accept-on
The second parameter of http.post() is a string, it will be in "Request Payload". 'Content-Type' can not be 'application/x-www-form-urlencoded'.
How to send right format of payload in Angular 2 since the php backend accept only 'x-www-form-urlencoded'? http://stackoverflow.com/questions/38375791/how-to-send-right-format-of-payload-in-angular-2-since-the-php-backend-accept-on
import { Http, Response,Headers, RequestOptions} from '@angular/http';
public getUserConfig():Observable<Response>{
let widgetUrl = '/api/getXConfig';
let data =encodeURI('jinData={"USERID":"Jin"}');
let options = new RequestOptions({
withCredentials: true
});
var headers = new Headers();
//
//headers.append('Content-Type', 'application/json');
//'application/x-www-form-urlencoded') can't send "Request Payload"
//headers.append('Content-Type', 'application/x-www-form-urlencoded');
// headers.append('Content-Type', 'text/plain; charset=utf-8');
options.headers=headers;
return this._http.post(
widgetUrl
,data //It will be in "Request Payload".
,options
);
}
public getUserConfig():Observable<Response>{
let widgetUrl = '/api/getXConfig';
let data =encodeURI('jinData={"USERID":"Jin"}');
let options = new RequestOptions({
withCredentials: true
});
var headers = new Headers();
//
//headers.append('Content-Type', 'application/json');
//'application/x-www-form-urlencoded') can't send "Request Payload"
//headers.append('Content-Type', 'application/x-www-form-urlencoded');
// headers.append('Content-Type', 'text/plain; charset=utf-8');
options.headers=headers;
return this._http.post(
widgetUrl
,data //It will be in "Request Payload".
,options
);
}
The second parameter of http.post() is a string, it will be in "Request Payload". 'Content-Type' can not be 'application/x-www-form-urlencoded'.
评论
发表评论