2Bbear's knowledge workshop

기존에 했었던 rest SDK 예제 코드를 이용하여 수정하였다.

============================================================

이번에는 respon된 값을 파일로 출력하는 것이 아닌 string으로 출력한다.


#include <cpprest/http_client.h>

#include <cpprest/filestream.h>


using namespace utility;

using namespace web;

using namespace web::http;

using namespace web::http::client;

using namespace concurrency::streams;


int main()

{

pplx::task<void> requestTask2{ []() 

{

std::cout << "1" << std::endl;

http_client_config conf;

conf.set_timeout(seconds(5));


http_client client(U("http://localhost:8080"));

uri_builder builder(U("/webgameserver/Login"));


http_response response = client.request(methods::GET, builder.to_string()).get();

std::cout << "2" << std::endl;

printf("Receive response status code:%u\n", response.status_code());


char ch = 0;

std::string str;

ch = response.body().read().get();

while (ch != -1)

{

str.push_back(ch);

ch = response.body().read().get();

}


std::cout << "respone : " << str << std::endl;


}};

try

{

requestTask2.wait();

}

catch (const std::exception &e)

{

printf("Error exception:%s\n", e.what());

}

       result 0;

}



원하는 형태로 값이 출력된 것을 확인 할 수 있다.