Monday, January 07, 2013 9:07 PM
I'm building a client to talk to a REST API build around the Symfony2 framework. As a standard for the framework form field names use a format of "formName[fieldName]"
So a post request might look like this:
If I try to pass something like that into client.request it throws an exception: pplx::invalid_operation, at ln:983 in http_msg.h
If I remove a the brackets, life is good. I've tried the URI builder, and when I called builder.to_encoded_string() it executes fine and doesn't throw an exception for the URI being invalid, only when I try to pass the string to generate a request. Considering this isn't actually a malformed uri, is there a way to work around this?
Wednesday, January 09, 2013 4:01 AM
The problem you encountered is definitely caused by the encode_uri function, which seems not working properly.
Directly encoding a given URI string by calling uri::encode_uri is hard, since each component of URI has different encoding policy, and by default the encode_uri function only take a least aggressive encoding strategy, which might miss some characters that should be encoded.
There are 2 solutions for you :
1. you can encode the query separately by invoking the uri::encode_component function, and concat the results together to construct an encoded uri string.
2. Construct uri by using uri_builder (our recommended way). Since the uri_builder has the knowledge of each part of the uri, it will encode the uri correctly (As you already experimented.)
Of course, we will try to improve the usability of uri encoding functions, and thanks for your feedback.
- Marked As Answer by Vapes Friday, January 11, 2013 5:39 PM
Thursday, January 10, 2013 8:59 PM
Thanks for the response. I hadn't realized I could build my own request and send it to client.request(), so using the uri_builder did the trick. Ultimately I found that for my use case I needed to pack the data in the body and send it as a form, but your information will help when I have to make similar requests with GET.