And thanks for the confirmation. I will try to find out why the two alternatives make a difference.
Bogdan Bogucki bbogucki@hussar.pl schrieb am Mi., 4. Juli 2018, 21:56:
Hello,
It works with body as a third parameter. Body has to be defined in http request because without that third parameter is ignored.
Working example:
for $x in http:send-request( <http:request method='post'> <http:header name="User-Agent" value="Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"/> <http:body media-type='application/x-www-form-urlencoded; charset=UTF-8'/> </http:request> ,'http:localhost:3333', 'start=0&length=100& ')[2]/data/results/content return $x
Thank you Christian for help.
Best Regards Bogdan Bogucki
-----Wiadomość oryginalna----- Od: Christian Grün [mailto:christian.gruen@gmail.com] Wysłano: 4 lipca 2018 18:31 Do: bbogucki@hussar.pl DW: BaseX Temat: Re: [basex-talk] http:send-request - problem with form data
Hi Bogdan,
I didn’t try it, but what happens if you specify the body as third argument?
Cheers, Christian
On Tue, Jul 3, 2018 at 10:14 PM Bogdan Bogucki bbogucki@hussar.pl wrote:
Hello,
I don't want pass values in query string. Server side expect parameters
in payload.
HTML Form parameters in POST method are passed in payload not in URI. This is the reason why I put parameters in body. Problem is escaping & character with & How can I force BaseX to not escape characters in
CDATA element ?
This is my code: <http:request method='post' href='http://localhost:3333%27%3E <http:header name="User-Agent" value="Mozilla/5.0 (Windows NT 6.1;
Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"/>
<http:body media-type='application/x-www-form-urlencoded;
charset=UTF-8'>
<![CDATA[start=0&length=100&sort=date_type&page=0&size=100]]> </http:body>
</http:request>
On server side I received following request:
POST / HTTP/1.1 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36 Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Host: copart.com:3333
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive Content-Length: 75
start=0&length=100&sort=date_type&page=0&size=100
I expect that CDATA will be not escaped, or I am wrong ?
Pozdrawiam Bogdan Bogucki
HUSSAR SYSTEMS
NIP: 532-170-12-00 Regon: 142624070
e-mail: bbogucki@hussar.pl tel. kom.: +48 607 409 301 www: www.hussar.pl
-----Wiadomość oryginalna----- Od: Christian Grün [mailto:christian.gruen@gmail.com] Wysłano: 3 lipca 2018 12:11 Do: bbogucki@hussar.pl DW: BaseX Temat: Re: [basex-talk] http:send-request - problem with form data
Hi Bogdan,
If you want your arguments parsed as HTTP query parameters, it should
suffice to attach them to the URL:
let $url := 'http://localhost:3333' let $params := ``[start=0&length=100&sort=date_type&page=0&size=100]`` return http:send-request( <http:request method='post' href='{ $url || '?' || $params }'> ...
If this is not what you need, you might need to give us more information
on how the request will be handled server-side (for example, do you use RESTXQ?).
Best, Christian
On Mon, Jul 2, 2018 at 11:11 PM Bogdan Bogucki bbogucki@hussar.pl
wrote:
Hello,
I have problem with http:send-request. I want to send post method
request with form data but I encountered problem with characters encoding.
Example:
Request:
for $x in http:send-request(
<http:request method='post' href=
<http:header name="User-Agent" value="Mozilla/5.0 (Windows NT
6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"/>
<http:body media-type='application/x-www-form-urlencoded;
charset=UTF-8'>
<![CDATA[start=0&length=100&sort=date_type&page=0&size=100]]> </http:body>
</http:request>
)[2]/json/data/results/content
return $x
Optimized Query:
util:item-at(http:send-request(element Q{
http://expath.org/ns/http-client%7Drequest { (attribute method { ("post") }, attribute href { ("http://localhost:3333") }, element Q{ http://expath.org/ns/http-client%7Dheader { (attribute name { ("User-Agent") }, attribute value { ("Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36") }) }, element Q{http://expath.org/ns/http-client%7Dbody { (attribute media-type { ("application/x-www-form-urlencoded; charset=UTF-8") }, "
 start=0&length=100&sort=date_type&page=0&size=100
 ") }) }), 2)/json/data/results/content
Request send:
POST / HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Host: copart.com:3333
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Content-Length: 75
start=0&length=100&sort=date_type&page=0&size=100
Payload is not correctly encoded it should be:
start=0&length=100&sort=date_type&page=0&size=100
How can I force function http:send-request to serialize CDATA without
escaping ?
Best Regards
Bogdan Bogucki