WinHttpQueryDataAvailable

WinHttpQueryDataAvailable

本文介绍了为什么WinHttpQueryDataAvailable说0字节可用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

同步操作. GetLastError = 0, WinHttpQueryDataAvailable 本身返回TRUE(即OK),但要读取的字节数= 0

Synchronous operation. GetLastError = 0, WinHttpQueryDataAvailable itself returns TRUE (i.e. OK) yet the number of bytes to read = 0

有什么意思吗?它通常可以正常工作(从相机读取JPEG流),但偶尔会卡在这里(这会提示代码重新连接).

Any idea what this means? It normally works fine (reading JPEG stream from a camera), but occasionally gets stuck here (which prompts the code to reconnect).

根据MSDN,不应返回 WinHttpQueryDataAvailable :如果会话是同步的,则请求将等到数据可用为止."

According to MSDN, WinHttpQueryDataAvailable shouldn't have returned: "If the session is synchronous, the request waits until data becomes available."

此处提取代码:

g_HSession = WinHttpOpen( L"Jet", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0 );

ResultsOk = WinHttpSendRequest(
    hRequest,
    WINHTTP_NO_ADDITIONAL_HEADERS,
    0, WINHTTP_NO_REQUEST_DATA, 0,
    0, 0);

// End the request.
if (ResultsOk)
{
    ResultsOk = WinHttpReceiveResponse( hRequest, NULL );

    DWORD BytesToRead = 0;

    if (WinHttpQueryDataAvailable( hRequest, &BytesToRead ))
    {
        if (BytesToRead) // THIS IS SOMETIMES 0 - seems wrong to me
        {
            if (WinHttpReadData( hRequest, pReadPos, min(BytesToRead, (unsigned)SizeRemaining), &NumRead ))
            {
                ...etc!

推荐答案

已成功接收基础HTTP响应,但该响应为空(即零长度响应),或者已读取并关闭了所有数据. WinHttpQueryDataAvailable 通过返回 TRUE 仍显示零数据可用量来表示这一点.

Underlying HTTP response has been successfully received, but it was empty (that is, zero length response) or all the data has been read and closed. WinHttpQueryDataAvailable indicates this by returning TRUE still showing zero count of data available.

考虑:

HTTP/1.0 200 OK
Content-Length: 0

这篇关于为什么WinHttpQueryDataAvailable说0字节可用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-24 18:19