I had a similar problem with Angular 1, so I understand how to implement it, only I miss the last step.
Like last time, the guy who made the backend for our application accepts requests with type application/x-www-form-urlencoded and is exactly the same as Angular 1, so Angular 2 sends them with type application/json .
What I did with ng1 was that in config I changed the http provider to run urlencoded over the body of each request.
In ng2, I see that there is https://angular.io/docs/ts/latest/api/http/BaseRequestOptions-class.html a BaseRequestOptions , which I believe is made specifically for this single documentation, a bit not there , so I'm not sure how to implement this correctly (I'm also new to TypeScript).
How to do this so that each of my post and other requests is sent as urlencoded at the end (I also want the function to run on the body so that it actually points to urlencoded).
In addition: why there is no simpler option for this, since now I see that both ASP.Net and Flask (so, I believe, many others) do not support application\json by default?
EDIT: I created a custom function that I use for every object I submit in the POST module, but I hope there is a simpler and more general solution.
import { URLSearchParams } from 'angular2/http'; export function urlEncode(obj: Object): string { let urlSearchParams = new URLSearchParams(); for (let key in obj) { urlSearchParams.append(key, obj[key]); } return urlSearchParams.toString(); }
and then i use it as
this.http.post('http://localhost:5000/user/auth/login', urlEncode(data))
angular typescript
ditoslav Jan 10 '16 at 11:05 2016-01-10 11:05
source share