Using FormData with http methods
See original GitHub issueHi! Is it possible to send formData with put, post, etc methods? When I have something like:
@Component({})
export class Foo {
public myForm: FormGroup;
constructor(private angular2TokenService: Angular2TokenService) {}
bar() {
let someFormData = new FormData();
Object.keys(this.myForm.value).forEach(k => {
someFormData.append(k, this.myForm.value[k]);
});
this.angular2TokenService.put('url', someFormData).subscribe(res => {
console.log(res);
});
}
}
I haven’t someFormData in my request.
I finded workaround for myself by using:
http.put
with all needed headers instead: tokenService.put
I do something like:
@Component({})
export class Foo {
public myForm: FormGroup;
constructor(private http: Http) {
this.headers = new Headers({
'accessToken': localStorage.getItem('accessToken'),
'client': localStorage.getItem('client'),
'expiry': localStorage.getItem('expiry'),
'tokenType': localStorage.getItem('tokenType'),
'uid': localStorage.getItem('uid')
});
}
bar() {
let someFormData = new FormData();
Object.keys(this.myForm.value).forEach(k => {
someFormData.append(k, this.myForm.value[k]);
});
this.http.put('url', someFormData, {headers: this.headers}).subscribe(res => {
console.log(res);
});
}
}
My angular2-token version is v0.1.17.
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (2 by maintainers)
Top Results From Across the Web
Which HTTP method is used to send the form-data
Sending the form data using the 'GET' HTTP method: The GET method is used to request data from specified resources. It sends an...
Read more >Sending form data - Learn web development | MDN
The HTTP protocol provides several ways to perform a request; HTML form data can be transmitted via a number of different methods, ...
Read more >Can HTTP method GET be used with "multipart/form-data ...
No. As GET requests don't have a body, specifying it's Content-Type doesn't make any sense. Especially multipart/form-data , which states ...
Read more >How to specify the HTTP method to use when sending form ...
Use the method attribute to specify the HTTP method to use when sending form-data in HTML.
Read more >FormData - The Modern JavaScript Tutorial
FormData objects are used to capture HTML form and submit it using fetch or another network method. We can either create new FormData(form)...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@NiekPas, he means using version 6.0.0-rc.0 of angular-token
https://github.com/neroniaky/angular2-token/tree/6.x https://www.npmjs.com/package/angular-token
We’re slowly migrating away from the current implementation and moving to a HttpInterceptor solution since that plays a lot nicer with HttpClient.
@artem-galas, you can use “request” method and append auth headers with {enctype: “multipart/form-data”}
example from my user-service class