기존에 했었던 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; } |
원하는 형태로 값이 출력된 것을 확인 할 수 있다.
'중단한 프로젝트 > WebServerGameProject(Team)' 카테고리의 다른 글
9. 서버 어플리케이션 서비스에 DBConnectionPool을 만들자 (0) | 2019.01.30 |
---|---|
8. 스프링 웹 어플리케이션 서비스에 request하면 db에 접속하는 기능을 만들자 (0) | 2019.01.30 |
6. cpprest , rest 라이브러리로 C++로 http 통신 구하기 (0) | 2019.01.29 |
5. Boost asio를 이용한 네트워크 통신 만들어보기 (0) | 2019.01.28 |
4. c++로 webservice에 연결하는 방법 (0) | 2019.01.24 |