2Bbear's knowledge workshop

드디어 찾았다 흙흙...

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

1. cpprestsdk 를 다운받기 위해 Window용 vcpkg를 다운 받아야합니다.

참고 : https://upglay.tistory.com/12


이 블로그를 따라서 vcpkg를 다운 받아 봅시다.


window 8,7,10 이상의 os가 필요하고

visual studio 2015, 2017이 필요합니다

Git을 설치해야합니다

Cmake를 설치해야합니다.


1. vcpkg 설치 (윈도우 기준)

https://upglay.tistory.com/12 로 들어가서 Zip 파일로 파일을 내려 받습니다.


2.C 드라이브에 vcpkg라는 폴더를 만들어 그 곳에 다운 받은 Zip압축을 풀어줍니다.


3. CMD 창으로 가서 c:\vcpkg\boostrap-vcpkg.bat를 치면 설치가 시작됩니다.


여기까지 됐으면 스탑.!


2. 이제 cpprestsdk라이브러리를 설치합시다.

참고 : https://github.com/Microsoft/cpprestsdk


1. CMD 창에서 vcpkg install cpprestsdk cpprestsdk:x64-windows 명령어를 칩니다.


2. 27분을 기다려줍니다.....설치하는게 너무 많....용량 9기가...


3. 설치가 다 되면 현재 켜진 모든 Visual Studio를 종료합니다.


4. 다시 CMD 창으로 돌아가서 vcpkg integrate install 명령어를 쳐줍니다.

이 명령어로 모든 Visual studio에 라이브러리가 통합됩니다. 한 마디로 굳이 링커 연결을 안해주어도 헤더파일을 끌어다 쓸 수 있따는 겁니다!!! 하와와와



3. Visual Studio에 새로운 c++ 프로젝트를 만들어서 코드를 테스트 해봅시다.


#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()

{

auto fileStream = std::make_shared<ostream>();


pplx::task<void> requestTask = fstream::open_ostream(U("result.html")).then([=](ostream outFile)

{

*fileStream = outFile;


http_client_config conf;

conf.set_timeout(seconds(5));


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

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

builder.append_query(U("q"), U("Casablanca CodePlex"));


return client.request(methods::GET, builder.to_string());

}).then([=](http_response response)

{

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


return response.body().read_to_end(fileStream->streambuf());

}).then([=](size_t nVal)

{

printf("Size is %u\n", nVal);


return fileStream->close();

});


try

{

requestTask.wait();

}

catch (const std::exception &e)

{

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

}


return 0;

}

 


이 코드가 하는 일이 뭐냐면...해당 포트와 패스로 접속해서 접속된 응답을 result.http로 바꾸는 코드입니다. 흠...고쳐야 할 부분이 많지만 일단 써봅시다.


client url 적는 부분에 호스트와 포트번호를 합쳐서 넣어줍니다.

그 뒤 builder에는 Path를 즉 경로를 넣어서 센드 해주면 

짜잔 하고 완성됩니다.


애초에 궁금하다면 웹 어플리케이션 서비스에 해당 접속이 이루어지면 반응하게 끔 하시면 알기 쉬울꺼에요




Login에 요청을 보내자 반응하는 모습입니다.






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

헐 이렇게 어렵게 설치하는 것 보다 이미 있는 rest sdk를 쓰는 게 좋지 않았을까.?..

https://psychoria.tistory.com/211

이분이 사용하시는거 보니...ㅠㅠ