http_client exception WinHttpSendRequest, WinHttpReceiveResponse

Oct 15, 2014 at 1:56 PM
Edited Oct 15, 2014 at 1:57 PM
I Using this Code to Http Post Calling

normal situation is success
but many thread call situation is intermittent Fail

  • [e.what():Error in: WinHttpReceiveResponse][GetLastError():997]
  • [e.what():Error in: WinHttpSendRequest][GetLastError():0]
  • [e.what():Error in: WinHttpSendRequest][GetLastError():1008]
  • [e.what():Error in: WinHttpReceiveResponse][GetLastError():0]


        bool HttpGameLog::httpGameLog(std::wstring& bodyData)
            http_client client(utility::string_t(SingletonURL::Instance().GetLogURL_Wide()));
            bodyData.insert(0, L"body=");
            client.request(methods::POST, SingletonURL::Instance().GetLogURL_Wide(), bodyData, L"application/x-www-form-urlencoded").then([=](pplx::task<http_response> task)
                    http_response response = task.get();
                    if (status_codes::OK != response.status_code())
                        GLOBALLOG_4(_FATAL, "HttpGameLog Stateus Code is not OK", SingletonURL::Instance().GetLogURL(), bodyData, response.status_code(), response.body());

                    auto bodyStream = response.body();
                    concurrency::streams::container_buffer<std::string> inStringBuffer;
                    bodyStream.read_to_end(inStringBuffer).then([=](size_t bytesRead)
                        const std::string &text = inStringBuffer.collection();
                        if (std::string::npos == text.find("OK"))
                            GLOBALLOG_1(_FATAL, "HttpGameLog Error", text);
                catch (const http_exception& e)
                    GLOBALLOG_5(_FATAL, "HttpGameLog Exception", e.what(), GetLastError(), SingletonSingletonURL::Instance().GetLogURL(), bodyData, e.error_code().message());
            return true;
How can I accomplish this??
Oct 22, 2014 at 11:10 PM
Hi ByoungInKim,

I'm not aware of any issues multi-threaded issues. Here are a couple of things I did notice in the code you have posted.
  1. The error codes you are printing out are incorrect. You can't call GetLastError() to retrieve it, there many have been several OS or other function calls since the one calling the error. We store the underlying error code and message inside the http_exception class. Take a look at the http_exception::error_code() API, it returns a std::error_code.
  2. Please note the read_to_end API is asynchronous, also if an exception occurs during the read you will end up with an unobserved exception. My recommendation would be to use a try/catch with a task based continuation like you've done for the http_client::request asynchronous call.