Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

form data unicode post request not work #1224

Closed
nvcken opened this issue Oct 27, 2014 · 8 comments
Closed

form data unicode post request not work #1224

nvcken opened this issue Oct 27, 2014 · 8 comments

Comments

@nvcken
Copy link

nvcken commented Oct 27, 2014

var options = {
url : 'http://example.com/abc',
method : 'POST',
headers : {
'content-type': 'application/x-www-form-urlencoded; charset=utf-8'
}
}

var r = request( options , function optionalCallback(err, httpResponse, body) { // ...

var form = r.form();
form.append('my_field', 'unicode character here');

After exec , the endpoint receive strange character value of "my_field"
What I am wrong?

@simov
Copy link
Member

simov commented Oct 27, 2014

What are you trying to achieve @nvcken ? Do you want a multipart encoded body or a urlencoded one?

@nvcken
Copy link
Author

nvcken commented Oct 27, 2014

@simov
I use multipart/form-data, as code above

@simov
Copy link
Member

simov commented Oct 27, 2014

Why are you passing wrong content-type then?

request.post('http://...', {
  formData: {
    my_field: 'something'
  }
}, function (err, res, body) {})

That should work, also take a look at the docs https://github.com/request/request#multipartform-data-multipart-form-uploads

@nvcken
Copy link
Author

nvcken commented Oct 27, 2014

ah, before set headers to options
I has try options with only url value ( has no headers ...) but It do not work. --- multipart/form-data
So then I try with options include headers , but still not work. ------ this seem wrong of urlencoded syntax.
I will try correct with urlencoded request.
but how can I use multipart/form-data with utf-8 on form value

@nvcken
Copy link
Author

nvcken commented Oct 27, 2014

@simov
I has try request with urlencoded, I edit my code like this sample
request.post({url:'http://service.com/upload', form: {key:'my unicode value'}}, function(err,httpResponse,body){ /* ... */ })
Then it work.

I have question is it possible make it work with multipart/form-data (formData) too ?

@simov
Copy link
Member

simov commented Oct 27, 2014

I have question is it possible make it work with multipart/form-data (formData) too ?

That depends on the service you use, unless it's your own server.

@nvcken
Copy link
Author

nvcken commented Oct 27, 2014

@simov
the service implement by java Jetty + spring, it receive with strange value , instead unicode value if I use multipart/form-data (formData) , it receives correct when I use urlencoded

@nylen
Copy link
Member

nylen commented Nov 10, 2014

looks like this has been resolved? let us know if that's not the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants