2012-10-31 2 views
0
내가 비주얼 스튜디오 2010와 CPP-NETLIB-0.9.4를 사용하고

내가 이렇게하는 기능 make_header를 통해 포스트 요청을 보낼 수 없습니다 :CPP-NETLIB

http::client::request* Interface::make_request_header(const string& uri) { 
    string url = host_ + uri; 
    string json_type = "application/json"; 
    http::client::request* req = new http::client::request(url); 
    req->add_header(make_pair("X-AUTH-TOKEN", token_)); 
    req->add_header(make_pair("Content-Type", json_type)); 
    req->add_header(make_pair("Accepts", json_type)); 
    return req; 
} 

GET 요청이 완벽하게 잘 작동 이는 다음과 같습니다 :

http::client client; 
http::client::request* req = make_request_header(my_uri); 
http::client::response res = client.get(*req); 

그러나 POST 요청은 예외/코어 덤프를 발생시킵니다. 그렇지 않으면 여러 번 확인하고 크롬 dev http 클라이언트 확장 때마다 작동하는 것으로 보인다. 내가 POST 요청에 사용하는 URL은 다음과 같습니다

위의 예에서
http://myhost.com/commands?query=my query 

, 나는

http::client client; 
http::client::request* req = make_request_header("http://myhost.com/commands?query=my query"); 
http::client::response res = client.post(*req); // FAILS AT THIS STEP. 

어떤 아이디어 왜하려고?

답변

2

쿼리 매개 변수는 공백을 포함 할 수 없으므로 URL 인코딩해야합니다.

공간

http://myhost.com/commands?query=my%20query 
과 같아야 쿼리에 %20입니다