Re: Is default Content-Type changed in a POST request?
[email protected] ("Octavian Rasnita") Wed, 27 May 2015 07:48:15 +0300
| Newsgroups | perl.libwww |
|---|---|
| Message-ID | <524FAD76C44B43C7955A95ED3AC9B074@ORasnita> |
------=_NextPart_000_000B_01D09851.7D6A8450 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Gisle Aas=20 On Mon, May 25, 2015 at 7:46 PM, Octavian Rasnita <[email protected]> = wrote: Hello, I set 2 default headers using default_header() method and one of = them is "Content-Type" which is set to "application/json", but it looks = that it is overidden with "application/x-www-form-urlencoded" when doing = a POST request. Is this intentionally? It's a consequence of how HTTP::Request::Common::POST() currently = works; $ua->post() is just a thin wrapper for that function. I guess = POST() could have been changed to not set the "Content-Type" if passed = scalar "Content". It currently defaults to = "application/x-www-form-urlencoded" which cause the outer default to not = apply. Changing this has the potential to break other code so it might = be better to accept this behaviour. Regards, Gisle Thanks Gisle. So there are historical reasons. I will create another wrapper in my code that sets that default = Content-Type just once. --Octavian ------=_NextPart_000_000B_01D09851.7D6A8450 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable =EF=BB=BF<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Dutf-8" http-equiv=3DContent-Type> <META name=3DGENERATOR content=3D"MSHTML 8.00.6001.23588"> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><B>From:</B> <A [email protected]=20 href=3D"mailto:[email protected]">Gisle Aas</A> </DIV> <BLOCKQUOTE=20 style=3D"BORDER-LEFT: #000000 2px solid; PADDING-LEFT: 5px; = PADDING-RIGHT: 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px"=20 dir=3Dltr> <DIV><FONT size=3D2 face=3DArial></FONT><FONT size=3D2 = face=3DArial></FONT><FONT=20 size=3D2 face=3DArial></FONT><FONT size=3D2 face=3DArial></FONT><FONT = size=3D2=20 face=3DArial></FONT><BR></DIV> <DIV dir=3Dltr> <DIV class=3Dgmail_extra> <DIV class=3Dgmail_quote>On Mon, May 25, 2015 at 7:46 PM, Octavian = Rasnita <SPAN=20 dir=3Dltr><<A href=3D"mailto:[email protected]"=20 target=3D_blank>[email protected]</A>></SPAN> wrote:<BR> <BLOCKQUOTE=20 style=3D"BORDER-LEFT: rgb(204,204,204) 1px solid; MARGIN: 0px 0px 0px = 0.8ex; PADDING-LEFT: 1ex"=20 class=3Dgmail_quote>Hello,<BR><BR>I set 2 default headers using=20 default_header() method and one of them is "Content-Type" which is = set to=20 "application/json", but it looks that it is overidden with=20 "application/x-www-form-urlencoded" when doing a POST request. Is = this=20 intentionally?<BR></BLOCKQUOTE> <DIV><FONT size=3D2 face=3DArial></FONT><BR></DIV> <DIV>It's a consequence of how HTTP::Request::Common::POST() currently = works;=20 $ua->post() is just a thin wrapper for that function. I guess = POST()=20 could have been changed to not set the "Content-Type" if passed scalar = "Content". It currently defaults to = "application/x-www-form-urlencoded"=20 which cause the outer default to not apply. Changing this has = the=20 potential to break other code so it might be better to accept this=20 behaviour.</DIV> <DIV><FONT size=3D2 face=3DArial></FONT><BR></DIV> <DIV>Regards,</DIV> <DIV>Gisle</DIV> <DIV><FONT size=3D2 face=3DArial></FONT><FONT size=3D2=20 face=3DArial></FONT><BR> </DIV> <DIV><FONT size=3D2 face=3DArial></FONT> </DIV> <DIV><FONT size=3D2 face=3DArial>Thanks Gisle. So there are historical = reasons.</FONT></DIV> <DIV><FONT size=3D2 face=3DArial>I will create another wrapper in my = code that=20 sets that default Content-Type just once.</FONT></DIV> <DIV><FONT size=3D2 face=3DArial></FONT> </DIV> <DIV><FONT size=3D2 face=3DArial>--Octavian</FONT></DIV> <DIV><FONT size=3D2=20 face=3DArial></FONT> </DIV></DIV></DIV></DIV></BLOCKQUOTE></BODY></H= TML> ------=_NextPart_000_000B_01D09851.7D6A8450--