From: Matt T. <mat...@gm...> - 2009-05-26 04:27:32
|
Hello folks, How are query parameters meant to be set with cpp-netlib? As a test I was trying to perform a GET to our Hudson (https://hudson.dev.java.net/) build server. The request looks something like this: http::request request("http://hudson_server/hudson/api/xml?xpath=//job[name='mainjob']/color/text()"); http::client client; http::response response; response = client.get(request); cout << body(response) << endl; The "/"'s in the xpath query cause problems. The parser in request.hpp (specifically, line 94) fails to match the "/" and discards the query parameters. [As an aside I appreciate that "/" is a reserved character in an URI but haven't dug far enough into the RFC (http://www.ietf.org/rfc/rfc3986.txt) to determine whether this usage of it makes for a valid URI. I *think* it is valid - even without escaping - based on section 3.4 but I'm not 100%.] I've worked around the issue with the following change: Index: boost/network/protocol/http/impl/request.hpp =================================================================== --- boost/network/protocol/http/impl/request.hpp (revision 142) +++ boost/network/protocol/http/impl/request.hpp (working copy) @@ -91,7 +91,7 @@ = construct_<typename string_traits<tag>::type>(arg1, arg2) ] >> !(ch_p('?') - >> (+(alnum_p | '&' | '=' | '%' | '_' ))[ + >> (+(anychar_p | '&' | '=' | '%' | '_' ))[ var(fusion::at_key<typename tags::query>(uri_parts)) = construct_<typename string_traits<tag>::type>(arg1, arg2) ] But that's quite dirty! I'm wondering if there's a better way to set queries for a request? I couldn't find anything in the code but I may well have missed something. I suppose I was looking for something like: http::request request("http://hudson_server/hudson/api/xml"); request.addQuery("xpath", "//job[name='mainjob']/color/text()") That way the parser could add the surrounding stuff (question marks, amperstands etc) for me. As it turns out this is similar to how Pion's HTTPRequest class handles queries. BTW I did notice there is a query() method to *return* the query string. I also noticed the "make_query_string" method but I wasn't sure if I could (or should) try and use it since it was in an impl file. It also doesn't seem to be used internally either though... Any comments? Am I doing something obviously wrong? Cheers, Matt |