C++ REST SDK??????÷?
???????????? ???????[ 2015/1/8 13:27:48 ] ????????C++ net
????????????get()?????????????????????????????????????????????????????rest sdk???????????????http????????????? http_client??????????????????http????rest api???????????????URL???????ЩURL???????????е?search?????п??????Щurl??????????????????uri_builder??????Щ???url??????????飬???????????
????uri_builder builder;
????builder.append_path(L"search"); //???URL
????builder.append_query(L"q"?? L"Casablanca CodePlex"); //???url????
??????url?????????????????????????????????????methods::GET??methods::POST??????
????client.request(methods::GET?? builder.to_string()).get();
??????????????в????request body??????????????http???????request body???????json????????????????????post json?????request body???????rest sdk????json??????????json??????????????
????uri_builder builder;
????builder.append_path(L"/test");
????json::value obj;
????obj[L"Count"] = json::value::number(6);
????obj[L"Version"] = json::value::string(L"1.0");
????client.request(methods::POST?? builder.to_string()?? obj.serialize()?? L"application/json");
???????request body??????????????????????????????
????wchar_t buf[48] = {};
????http_response response = client.request(methods::POST?? builder.to_string()?? buf/*L""*/?? L"application/octet-stream").get();
??????????????http??????rest api???????????json?????????????????????json????rest sdk????http_response???????????????????http????????????????
{
"result":"service failed"
"error_code": 400
}
http?????????
if (response.status_code() == status_codes::OK)
{
try
{
result = true;
const json::value& jv = response.extract_json().get();
const web::json::object& jobj = jv.as_object();
auto result = jobj.at(L"result").as_string();
auto access_code = result.as_object().at(L"error_code").as_string();
wcout << result<<" "<< access_code << endl;
}
catch (const std::exception& e)
{
cout << e.what() << endl;
}
}
|
??????wcout???????????????????????????????????????????
????wcout.imbue(locale("chs"));//?????
?????????????????????http?????http_client???????????30?????????????????ó?????
????http_client_config config;
????config.set_timeout(utility::seconds(90)); //?????90???
????http_client client(URL?? config);
??????????????C++ REST SDK???÷????????uri???????????json???????????????????????????????????????????????????????C++ REST SDK?????????????????????????о???
?????????????????????????c++??????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11