what is application/x-json?

Jun 16, 2014 at 4:27 PM
client.request(methods::POST, L"", L"arsId=09286", L"application/x-www-form-urlencoded")

error is caught like below
Content-Type must be JSON to extract (is : application/x-json)

I don't know why this error occur.
Jun 16, 2014 at 10:35 PM
Hi bongdragon,

application/x-json is a MIME type (see http://en.wikipedia.org/wiki/MIME for more details on that). Casablanca expects that JSON payloads will have a MIME type of either application/json (the official MIME type for JSON), text/json, text/x-json, text/javascript, text/x-javascript, application/javascript, or application/x-javascript.

If you control the website you're connecting to, you should change the returned MIME type to application/json. If you do not control the website, you can work around this by using extract_string instead of extract_json and then passing it to
json::value obj = json::value::parse(extracted_string);
Jun 17, 2014 at 12:41 AM
thank you for reply

I try to change extract_string, but I encounter another problem
error code is like below
Content-type must be textual to extract a string

I want to get this data.
Jun 18, 2014 at 10:52 PM
Hi bongdragon,

Sorry for the incorrect suggestion last time. To clarify the reason why it did not work: extract_string() requires a MIME type that begins with "text/" (so your application/x-json doesn't work).

However, what should work is using the extract_vector() method. This will give you a vector of unsigned char. Then, you can use utility::conversions::to_string_t(std::string(v.begin(), v.end())) to convert it into a string_t. Finally, you can call json::value::parse(extracted_string) on the result to parse it into a JSON data structure.

auto v = response.extract_vector();
auto s = utility::conversions::to_string_t(std::string(v.begin(), v.end()));
json::value val = json::value::parse(s);
This workaround is inefficient, so we'll look at fixing this in the future.