-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Description
It is a simple code to test this issue (or as designed feature):
#include <cpprest/http_client.h>
using namespace web::http;
int main() {
try {
auto client = client::http_client{ U("https://jsonplaceholder.typicode.com/") };
auto request = http_request{ methods::POST };
request.set_request_uri(U("/posts"));
web::json::value requestData;
requestData[L"title"] = web::json::value::string(U("hello!"));
requestData[L"body"] = web::json::value::string(U("It is a salutation..."));
requestData[L"userId"] = web::json::value::number(100);
request.set_body(requestData);
auto response = client.request(request).get();
// here request has no body, but other attributes of it such as headers are remained unchanged
std::wcout << response.status_code() << std::endl;
}
catch (std::exception& e) {
std::cout << e.what() << std::endl;
}
return 0;
}Why after calling http_client::request(http_request) the body is being emptied? The argument is passed by value and I expect no side effects on it. I guess that the root of this behavior is in using a shared istream (i.e. http_msg_base::m_inStream) between instances of copied http_request that its data is consumed in call to http_client::request(http_request). But it is confusing and against principle of least astonishment.
Metadata
Metadata
Assignees
Labels
No labels