Quantcast
Channel: WE MOVED to github.com/microsoft/cpprestsdk. This site is not monitored!
Viewing all articles
Browse latest Browse all 4845

New Post: http_client exception WinHttpSendRequest, WinHttpReceiveResponse

$
0
0
I Using this Code to Http Post Calling

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

exception
  • [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]

Code

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)
            {
                try
                {
                    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());
                        return;
                    }

                    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());
                }
            });
            returntrue;
        }
How can I accomplish this??
Thanks

Viewing all articles
Browse latest Browse all 4845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>