Is it possible to use an empty header value in HttpAddRequestHeaders()?

52 views Asked by At

I am trying to use WinInet as an HTTP client, and some requests require empty headers, but various attempts at invocation always return parameter errors.

I haven't found any relevant instructions in the corresponding documentation, but according to the HTTP RFC definitions, an empty header value should be valid. Therefore, I'm not sure whether it's because WinInet doesn't support it, or if there's an issue with the way I'm using it.

The related codes:

//***
if (!HttpAddRequestHeadersA(hRequest, "EmptyHeader01:\t\r\n",
    (ULONG)-1L, HTTP_ADDREQ_FLAG_ADD)) {
    std::cout << "HttpAddRequestHeadersA [EmptyHeader01:\t\r\n] failed with error: " << GetLastError() << std::endl;
}


if (!HttpAddRequestHeadersA(hRequest, "EmptyHeader01:\r\n",
    (ULONG)-1L, HTTP_ADDREQ_FLAG_ADD)) {
    std::cout << "HttpAddRequestHeadersA [EmptyHeader01:\r\n] failed with error: " << GetLastError() << std::endl;
}

if (!HttpAddRequestHeadersA(hRequest, "EmptyHeader01:",
    (ULONG)-1L, HTTP_ADDREQ_FLAG_ADD)) {
    std::cout << "HttpAddRequestHeadersA [EmptyHeader01:] failed with error: " << GetLastError() << std::endl;
}

if (!HttpAddRequestHeadersA(hRequest, "EmptyHeader01: ",
    (ULONG)-1L, HTTP_ADDREQ_FLAG_ADD)) {
    std::cout << "HttpAddRequestHeadersA [EmptyHeader01: ] failed with error: " << GetLastError() << std::endl;
}
//***
0

There are 0 answers