Setting request encoding

122 views
Skip to first unread message

Jorge

unread,
Sep 26, 2009, 6:45:08 PM9/26/09
to ASIHTTPRequest
I'm trying to post a form using ASIHTTPRequest this way:

ASIFormDataRequest *request = [[[ASIFormDataRequest alloc]
initWithURL:url] autorelease];
[request setPostValue:self.name forKey:@"Name"];

Problem is the script on the server expects data formated in ISOLatin1
and the request data is being sent UTF8 encoded. How can i change the
encoding of the request data?

Thank you!!

Maarten Billemont

unread,
Sep 27, 2009, 4:20:40 AM9/27/09
to asihttp...@googlegroups.com
ASIHttpRequest does not currently support specifying custom
encodings. I personally recommend configuring your server to respect
Content-Type headers (which I'm not sure ASIHttpRequest's
FormDataRequest sets, I modified it to do so). Your server should
either way respect this header and convert whatever input data it gets
from its encoding to the encoding that it operates in.

See attached patch to add UTF-8 encoding to the content-header of the
request (UTF-8 because that's how ASIHttpRequest encodings your string
data). Then it's up to the webserver to convert its bytestream to the
correct characters based on the Content-Type header.

encoding.patch

Jorge

unread,
Sep 27, 2009, 4:33:28 AM9/27/09
to ASIHTTPRequest
Problem is I cant modify the webserver cause I'm not the
administrator. It's just a service I use from my App.

How do I apply that patch?

Thank you
>  encoding.patch
> < 1 KBVerDescargar

Maarten Billemont

unread,
Sep 27, 2009, 4:38:48 AM9/27/09
to asihttp...@googlegroups.com
If the server behaves correctly; you won't need to modify it. Chances
are it just interpretes ASIHttpRequest's bytestream as ISO-8859-1
because it fails to specify the true encoding of its data. Therefore,
the patch could fix the issue for you.

You apply a patch by running the ''patch -p0 < path-to-the-patchfile''
command on terminal in the directory of the ASIHttpRequest classes.
''man patch'' explains how patching works. Alternatively, you can
wait until this is fixed in ASIHttpRequest itself.

Jorge

unread,
Sep 27, 2009, 5:19:07 AM9/27/09
to ASIHTTPRequest
Thanks Maarten.

I'm having trouble applying the patch:

$ patch -p0 <~/Downloads/temp/encoding.patch
patch unexpectedly ends in middle of line
patch: **** Only garbage was found in the patch input.

Jorge

unread,
Sep 27, 2009, 5:19:55 AM9/27/09
to ASIHTTPRequest
Thanks Maarten.

I'm having trouble applying the patch:

$ patch -p0 <~/Downloads/temp/encoding.patch
patch unexpectedly ends in middle of line
patch: **** Only garbage was found in the patch input.

On 27 sep, 10:38, Maarten Billemont <lhun...@gmail.com> wrote:

Maarten Billemont

unread,
Sep 27, 2009, 4:20:15 PM9/27/09
to asihttp...@googlegroups.com
You can also check out my github fork instead:
<http://github.com/lhunath/asi-http-request
>

Sent from my iPhone

Jorge

unread,
Sep 28, 2009, 6:21:59 AM9/28/09
to ASIHTTPRequest
Hi Maarten.

I tried the updated version of and it's not working either.

I modified it to use NSISOLatin1StringEncoding and iso-8859-1 as
charset and everything is working right now.

I don't know if it's an error in the server but it would be
interesting to add the chance of specifying the encoding of the
requests in future versions.

Thank you.

On 27 sep, 22:20, Maarten Billemont <lhun...@gmail.com> wrote:
> You can also check out my github fork instead:
> <http://github.com/lhunath/asi-http-request
>  >
>
> Sent from my iPhone
>
> On 27 Sep 2009, at 11:20, Jorge <jorfe...@gmail.com> wrote:
>
>
>
> > Thanks Maarten.
>
> > I'm having trouble applying the patch:
>
> > $ patch -p0 <~/Downloads/temp/encoding.patch
> > patch unexpectedly ends in middle of line
> > patch: **** Only garbage was found in the patch input.
>
> > On 27 sep, 10:38, Maarten Billemont <lhun...@gmail.com> wrote:
> >> If the server behaves correctly; you won't need to modify it.
> >> Chances
> >> are it just interpretes ASIHttpRequest's bytestream as ISO-8859-1
> >> because it fails to specify the trueencodingof its data.
> >> Therefore,
> >> the patch could fix the issue for you.
>
> >> You apply a patch by running the ''patch -p0 < path-to-the-
> >> patchfile''
> >> command on terminal in the directory of the ASIHttpRequest classes.
> >> ''man patch'' explains how patching works.  Alternatively, you can
> >> wait until this is fixed in ASIHttpRequest itself.
>
> >> On 27 Sep 2009, at 10:33, Jorge wrote:
>
> >>> Problem is I cant modify the webserver cause I'm not the
> >>> administrator. It's just a service I use from my App.
>
> >>> How do I apply that patch?
>
> >>> Thank you
>
> >>> On 27 sep, 10:20, Maarten Billemont <lhun...@gmail.com> wrote:
> >>>> ASIHttpRequest does not currently support specifying custom
> >>>> encodings.  I personally recommend configuring your server to
> >>>> respect
> >>>> Content-Type headers (which I'm not sure ASIHttpRequest's
> >>>> FormDataRequest sets, I modified it to do so).  Your server should
> >>>> either way respect this header and convert whatever input data it
> >>>> gets
> >>>> from itsencodingto theencodingthat it operates in.
>
> >>>> See attached patch to add UTF-8encodingto the content-header of
> >>>> the
> >>>> request (UTF-8 because that's how ASIHttpRequest encodings your
> >>>> string
> >>>> data).  Then it's up to the webserver to convert its bytestream to
> >>>> the
> >>>> correct characters based on the Content-Type header.
>
> >>>>  encoding.patch
> >>>> < 1 KBVerDescargar
>
> >>>> On 27 Sep 2009, at 00:45, Jorge wrote:
>
> >>>>> I'm trying to post a form using ASIHTTPRequest this way:
>
> >>>>> ASIFormDataRequest *request = [[[ASIFormDataRequest alloc]
> >>>>> initWithURL:url] autorelease];
> >>>>> [request setPostValue:self.name forKey:@"Name"];
>
> >>>>> Problem is the script on the server expects data formated in
> >>>>> ISOLatin1
> >>>>> and the request data is being sent UTF8 encoded. How can i change
> >>>>> the
> >>>>>encodingof the request data?
>
> >>>>> Thank you!!

Maarten Billemont

unread,
Sep 28, 2009, 6:23:31 AM9/28/09
to asihttp...@googlegroups.com
Then I recommend you bring it up at:
http://github.com/pokeb/asi-http-request/issues

Jorge

unread,
Sep 28, 2009, 6:41:21 AM9/28/09
to ASIHTTPRequest
Done

Thank you!

Ben Copsey

unread,
Sep 30, 2009, 3:59:54 PM9/30/09
to asihttp...@googlegroups.com
>> Then I recommend you bring it up at:http://github.com/pokeb/asi-
>> http-request/issues
>>

> Done

>>> I tried the updated version of and it's not working either.
>>
>>> I modified it to use NSISOLatin1StringEncoding and iso-8859-1 as
>>> charset and everything is working right now.
>>
>>> I don't know if it's an error in the server but it would be
>>> interesting to add the chance of specifying the encoding of the
>>> requests in future versions.

Thanks for this, will look at it in the next couple of days. It does
sound as though making the charset used by multipart/form-data
requests configurable (and not just telling the server it's UTF8)
might be worthwhile.

Best

Ben

Jorge

unread,
Oct 1, 2009, 2:37:30 AM10/1/09
to ASIHTTPRequest
Yes... you have to change both:

- The content type sent to the server
- The encoding of the form fields

Ben Copsey

unread,
Oct 3, 2009, 9:36:41 AM10/3/09
to asihttp...@googlegroups.com
>> Thanks for this, will look at it in the next couple of days. It does
>> sound as though making the charset used by multipart/form-data
>> requests configurable (and not just telling the server it's UTF8)
>> might be worthwhile.

Ok, this is in the newest version on GitHub, please let me know if you
find problems.

Ta

Ben

Reply all
Reply to author
Forward
0 new messages