cpprest SDK & json problem PLEASE HELP
Oct 11, 2017 at 9:54pm UTC
Hi experts
I try to get json from this link
http://34.233.163.236:8080/dctm-rest/services with no success. I spent all day searching debuging and now I lose all my patience. I just need help cos I am stuck here.
My code below always catch Content-Type error even if I set the json conent type and I get json content type so I really dont understand what is going on here. The server is already running so you can use this snippet to access the json.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
pplx::task<void > RequestJSONValueAsync()
{
http_client client(U("http://34.233.163.236:8080/dctm-rest/services" ));
http_request request(methods::GET);
request.headers().set_content_type(L"application/json" );
request.headers().add(L"Authorization" , L"Basic ZG1hZG1pbjpwYXNzd29yZA==" );
return client.request(request).then([=](http_response response) -> pplx::task<json::value>
{
std::wostringstream stream;
stream.str(std::wstring());
stream << L"Content type: " << response.headers().content_type() << std::endl;
stream << L"Content length: " << response.headers().content_length() << L"bytes" << std::endl;
std::wcout << stream.str();
if (response.status_code() == status_codes::OK)
{
return response.extract_json();
}
return pplx::task_from_result(json::value());
})
.then([=](pplx::task<json::value> previousTask)
{
try
{
const json::value& v = previousTask.get(); // here crashes and jump to catch with mentioned error
// Perform actions here to process the JSON value...
}
catch (const http_exception& e)
{
// error Contetn-type
}
});
}
Last edited on Oct 11, 2017 at 10:01pm UTC
Oct 12, 2017 at 11:04am UTC
Are you sure your url is correct?
When I try to access it with the browser I get time out error
Oct 12, 2017 at 10:20pm UTC
Sorry It is becouse the server allows only specific IP address so I have no permission to change it . So you cannot try it with my link.
Topic archived. No new replies allowed.