http:request post parameter bug? basex 7.01
Thursday, 12 January 2012 · 8 messages · last reply 15 Jan 2012
AB
Andy Bunce12 Jan 2012 15:37 #
Hi,
Could there be an encoding issue with http:request post requests?
I send..
let $r:=<http:request method='post' >
<http:body media-type="application/x-www-form-urlencoded"
method="text">a=3&b=4</http:body>
</http:request>
return http:send-request($r,"http://posttestserver.com/post.php")[2]http://www.posttestserver.com/ reports the parameters as..
Post Params:
key: 'a' value: '3'
key: 'amp;b' value: '4'
Empty post body.
/Andy
CG
Christian Grün13 Jan 2012 17:49 #
Hi Andy,
sorry for the late feedback.
Quoted text · Andy Bunce · 7 lines
> Could there be an encoding issue with http:request post requests? > I send.. > let $r:=<http:request method='post' > > <http:body media-type="application/x-www-form-urlencoded" > method="text">a=3&b=4</http:body> > </http:request> > return http:send-request($r,"http://posttestserver.com/post.php")[2]
You may be successful by additionally encoding "&" as "&" (didn't try it, though):
let $r:=<http:request method='post' >
<http:body media-type="application/x-www-form-urlencoded"
method="text">a=3&amp;b=4</http:body>
</http:request>Christian
AB
Andy Bunce13 Jan 2012 22:46 #
Heading in wrong direction ;-)
http://www.posttestserver.com/data/2012/01/13/13.44.241401974484 /Andy
On Fri, Jan 13, 2012 at 4:49 PM, Christian Grün
<christian.gruen at gmail.com>wrote:
Quoted text · Christian Grün · 22 lines
> Hi Andy, > > sorry for the late feedback. > > > Could there be an encoding issue with http:request post requests? > > I send.. > > let $r:=<http:request method='post' > > > <http:body media-type="application/x-www-form-urlencoded" > > method="text">a=3&b=4</http:body> > > </http:request> > > return http:send-request($r,"http://posttestserver.com/post.php")[2] > > You may be successful by additionally encoding "&" as "&" (didn't > try it, though): > > let $r:=<http:request method='post' > > <http:body media-type="application/x-www-form-urlencoded" > method="text">a=3&amp;b=4</http:body> > </http:request> > > Christian >
CG
Christian Grün13 Jan 2012 23:07 #
Well, yes.. I'll have a closer look at that soon!
Quoted text · Andy Bunce · 32 lines
> Heading in wrong direction ;-) > > http://www.posttestserver.com/data/2012/01/13/13.44.241401974484 > /Andy > > > On Fri, Jan 13, 2012 at 4:49 PM, Christian Grün <christian.gruen at gmail.com> > wrote: >> >> Hi Andy, >> >> sorry for the late feedback. >> >> > Could there be an encoding issue with http:request post requests? >> > I send.. >> > let $r:=<http:request method='post' > >> > <http:body media-type="application/x-www-form-urlencoded" >> > method="text">a=3&b=4</http:body> >> > </http:request> >> > return http:send-request($r,"http://posttestserver.com/post.php")[2] >> >> You may be successful by additionally encoding "&" as "&" (didn't >> try it, though): >> >> let $r:=<http:request method='post' > >> <http:body media-type="application/x-www-form-urlencoded" >> method="text">a=3&amp;b=4</http:body> >> </http:request> >> >> Christian > >
CG
Christian Grün14 Jan 2012 13:29 #
Hi Andy,
true, my hint was pretty pointless ;) I looked at the http
specification and our implementation, and I'm still not quite sure how the given case is to be correctly handled. The specification says that the request contents needs to be serialized, similar to the
serialization of any other contents [1]. Because of this, ampersands and other characters are encoded (which is wrong for the given case), and not decoded by the receiving web server (which is correct). It seems that similar problems have already been discussed on the EXPath mailing list [2], so it may be that the specification has to be revised.
A possible workaround is provided by the serialization parameter "format=no" in BaseX; this way, none of the entities will be encoded by the serializer:
let $r:=<http:request method='post' >
<http:body media-type="application/x-www-form-urlencoded"
format="no">a=3&b=4</http:body>
</http:request>
return http:send-request($r,"http://posttestserver.com/post.php")[2]Hope this helps,
Christian
[1] http://expath.org/spec/http-client#d2e362
[2] http://groups.google.com/group/expath/browse_thread/thread/91a795e59a92095f/8d37971df0276654
Quoted text · Christian Grün · 36 lines
On Fri, Jan 13, 2012 at 11:07 PM, Christian Grün <christian.gruen at gmail.com> wrote: > Well, yes.. I'll have a closer look at that soon! > >> Heading in wrong direction ;-) >> >> http://www.posttestserver.com/data/2012/01/13/13.44.241401974484 >> /Andy >> >> >> On Fri, Jan 13, 2012 at 4:49 PM, Christian Grün <christian.gruen at gmail.com> >> wrote: >>> >>> Hi Andy, >>> >>> sorry for the late feedback. >>> >>> > Could there be an encoding issue with http:request post requests? >>> > I send.. >>> > let $r:=<http:request method='post' > >>> > <http:body media-type="application/x-www-form-urlencoded" >>> > method="text">a=3&b=4</http:body> >>> > </http:request> >>> > return http:send-request($r,"http://posttestserver.com/post.php")[2] >>> >>> You may be successful by additionally encoding "&" as "&" (didn't >>> try it, though): >>> >>> let $r:=<http:request method='post' > >>> <http:body media-type="application/x-www-form-urlencoded" >>> method="text">a=3&amp;b=4</http:body> >>> </http:request> >>> >>> Christian >> >>
AB
Andy Bunce14 Jan 2012 15:56 #
Hi Christian
"format=no" works for me. Thanks.
I will need to take a look at what the EXPath HTTP Client Module spec is saying, as it seems like a real problem with the spec if it can not deal with this common case.
/Andy
On Sat, Jan 14, 2012 at 12:29 PM, Christian Grün
<christian.gruen at gmail.com>wrote:
Quoted text · Christian Grün · 69 lines
> Hi Andy, > > true, my hint was pretty pointless ;) I looked at the http > specification and our implementation, and I'm still not quite sure how > the given case is to be correctly handled. The specification says that > the request contents needs to be serialized, similar to the > serialization of any other contents [1]. Because of this, ampersands > and other characters are encoded (which is wrong for the given case), > and not decoded by the receiving web server (which is correct). It > seems that similar problems have already been discussed on the EXPath > mailing list [2], so it may be that the specification has to be > revised. > > A possible workaround is provided by the serialization parameter > "format=no" in BaseX; this way, none of the entities will be encoded > by the serializer: > > let $r:=<http:request method='post' > > <http:body media-type="application/x-www-form-urlencoded" > format="no">a=3&b=4</http:body> > </http:request> > return http:send-request($r,"http://posttestserver.com/post.php")[2] > > Hope this helps, > Christian > > [1] http://expath.org/spec/http-client#d2e362 > [2] > http://groups.google.com/group/expath/browse_thread/thread/91a795e59a92095f/8d37971df0276654 > ___________________________ > > On Fri, Jan 13, 2012 at 11:07 PM, Christian Grün > <christian.gruen at gmail.com> wrote: > > Well, yes.. I'll have a closer look at that soon! > > > >> Heading in wrong direction ;-) > >> > >> http://www.posttestserver.com/data/2012/01/13/13.44.241401974484 > >> /Andy > >> > >> > >> On Fri, Jan 13, 2012 at 4:49 PM, Christian Grün < > christian.gruen at gmail.com> > >> wrote: > >>> > >>> Hi Andy, > >>> > >>> sorry for the late feedback. > >>> > >>> > Could there be an encoding issue with http:request post requests? > >>> > I send.. > >>> > let $r:=<http:request method='post' > > >>> > <http:body media-type="application/x-www-form-urlencoded" > >>> > method="text">a=3&b=4</http:body> > >>> > </http:request> > >>> > return http:send-request($r,"http://posttestserver.com/post.php")[2] > >>> > >>> You may be successful by additionally encoding "&" as "&" (didn't > >>> try it, though): > >>> > >>> let $r:=<http:request method='post' > > >>> <http:body media-type="application/x-www-form-urlencoded" > >>> method="text">a=3&amp;b=4</http:body> > >>> </http:request> > >>> > >>> Christian > >> > >> >
CG
Christian Grün14 Jan 2012 17:54 #
Andy,
I was surprised to find out that our entity handling for the "text" method is not 100% conformant with the specification. We'll have a closer look at this, and after that, method='text' should work as expected.
Sorry for the confusion and thanks again for reporting the issue, Christian
Quoted text · Andy Bunce · 84 lines
On Sat, Jan 14, 2012 at 3:56 PM, Andy Bunce <bunce.andy at gmail.com> wrote: > Hi Christian > > "format=no" works for me. Thanks. > > I will need to take a look at what the EXPath HTTP Client Module spec is > saying, as it seems like a real problem with the spec if it can not deal > with this common case. > > /Andy > > On Sat, Jan 14, 2012 at 12:29 PM, Christian Grün <christian.gruen at gmail.com> > wrote: >> >> Hi Andy, >> >> true, my hint was pretty pointless ;) I looked at the http >> specification and our implementation, and I'm still not quite sure how >> the given case is to be correctly handled. The specification says that >> the request contents needs to be serialized, similar to the >> serialization of any other contents [1]. Because of this, ampersands >> and other characters are encoded (which is wrong for the given case), >> and not decoded by the receiving web server (which is correct). It >> seems that similar problems have already been discussed on the EXPath >> mailing list [2], so it may be that the specification has to be >> revised. >> >> A possible workaround is provided by the serialization parameter >> "format=no" in BaseX; this way, none of the entities will be encoded >> by the serializer: >> >> let $r:=<http:request method='post' > >> <http:body media-type="application/x-www-form-urlencoded" >> format="no">a=3&b=4</http:body> >> </http:request> >> return http:send-request($r,"http://posttestserver.com/post.php")[2] >> >> Hope this helps, >> Christian >> >> [1] http://expath.org/spec/http-client#d2e362 >> [2] >> http://groups.google.com/group/expath/browse_thread/thread/91a795e59a92095f/8d37971df0276654 >> ___________________________ >> >> On Fri, Jan 13, 2012 at 11:07 PM, Christian Grün >> <christian.gruen at gmail.com> wrote: >> > Well, yes.. I'll have a closer look at that soon! >> > >> >> Heading in wrong direction ;-) >> >> >> >> http://www.posttestserver.com/data/2012/01/13/13.44.241401974484 >> >> /Andy >> >> >> >> >> >> On Fri, Jan 13, 2012 at 4:49 PM, Christian Grün >> >> <christian.gruen at gmail.com> >> >> wrote: >> >>> >> >>> Hi Andy, >> >>> >> >>> sorry for the late feedback. >> >>> >> >>> > Could there be an encoding issue with http:request post requests? >> >>> > I send.. >> >>> > let $r:=<http:request method='post' > >> >>> > <http:body media-type="application/x-www-form-urlencoded" >> >>> > method="text">a=3&b=4</http:body> >> >>> > </http:request> >> >>> > return http:send-request($r,"http://posttestserver.com/post.php")[2] >> >>> >> >>> You may be successful by additionally encoding "&" as "&" (didn't >> >>> try it, though): >> >>> >> >>> let $r:=<http:request method='post' > >> >>> <http:body media-type="application/x-www-form-urlencoded" >> >>> method="text">a=3&amp;b=4</http:body> >> >>> </http:request> >> >>> >> >>> Christian >> >> >> >> > >
CG
The problem has been fixed in the latest snapshot. You may now use method='text' again (..and the EXPath http-client specification doesn't have any issues to be resolved).
Quoted text · Andy Bunce · 84 lines
On Sat, Jan 14, 2012 at 3:56 PM, Andy Bunce <bunce.andy at gmail.com> wrote: > Hi Christian > > "format=no" works for me. Thanks. > > I will need to take a look at what the EXPath HTTP Client Module spec is > saying, as it seems like a real problem with the spec if it can not deal > with this common case. > > /Andy > > On Sat, Jan 14, 2012 at 12:29 PM, Christian Grün <christian.gruen at gmail.com> > wrote: >> >> Hi Andy, >> >> true, my hint was pretty pointless ;) I looked at the http >> specification and our implementation, and I'm still not quite sure how >> the given case is to be correctly handled. The specification says that >> the request contents needs to be serialized, similar to the >> serialization of any other contents [1]. Because of this, ampersands >> and other characters are encoded (which is wrong for the given case), >> and not decoded by the receiving web server (which is correct). It >> seems that similar problems have already been discussed on the EXPath >> mailing list [2], so it may be that the specification has to be >> revised. >> >> A possible workaround is provided by the serialization parameter >> "format=no" in BaseX; this way, none of the entities will be encoded >> by the serializer: >> >> let $r:=<http:request method='post' > >> <http:body media-type="application/x-www-form-urlencoded" >> format="no">a=3&b=4</http:body> >> </http:request> >> return http:send-request($r,"http://posttestserver.com/post.php")[2] >> >> Hope this helps, >> Christian >> >> [1] http://expath.org/spec/http-client#d2e362 >> [2] >> http://groups.google.com/group/expath/browse_thread/thread/91a795e59a92095f/8d37971df0276654 >> ___________________________ >> >> On Fri, Jan 13, 2012 at 11:07 PM, Christian Grün >> <christian.gruen at gmail.com> wrote: >> > Well, yes.. I'll have a closer look at that soon! >> > >> >> Heading in wrong direction ;-) >> >> >> >> http://www.posttestserver.com/data/2012/01/13/13.44.241401974484 >> >> /Andy >> >> >> >> >> >> On Fri, Jan 13, 2012 at 4:49 PM, Christian Grün >> >> <christian.gruen at gmail.com> >> >> wrote: >> >>> >> >>> Hi Andy, >> >>> >> >>> sorry for the late feedback. >> >>> >> >>> > Could there be an encoding issue with http:request post requests? >> >>> > I send.. >> >>> > let $r:=<http:request method='post' > >> >>> > <http:body media-type="application/x-www-form-urlencoded" >> >>> > method="text">a=3&b=4</http:body> >> >>> > </http:request> >> >>> > return http:send-request($r,"http://posttestserver.com/post.php")[2] >> >>> >> >>> You may be successful by additionally encoding "&" as "&" (didn't >> >>> try it, though): >> >>> >> >>> let $r:=<http:request method='post' > >> >>> <http:body media-type="application/x-www-form-urlencoded" >> >>> method="text">a=3&amp;b=4</http:body> >> >>> </http:request> >> >>> >> >>> Christian >> >> >> >> > >
Written for BaseX 7.0. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery