I am implementing a web server using Ms http server api
v2 (in synchronous mode), and I am trying to test it from a web browser.
I send a GET request from the browser to http://localhost:50000/uri/ and my application receives it correctly. Then I send the response, with some data in a (HTTP_DATA_CHUNK
) using the HttpSendHttpResponse
, and I get 131 bytes sent. However, the browser is not receiving any data.
I have also tested it with wininet
client with the same result.
This is my send response code (Smalltalk):
sendResponse: aString
| data response sent id return |
data := HTTP_DATA_CHUNK external
data
DataChunkType: 0;
pBuffer: aString copyToExternalMemory;
BufferLength: aString size.
response := HTTP_RESPONSE_V2 external.
response
version1;
StatusCode: HTTP_STATUS_OK;
reason: 'Ok';
ContentType: 'text/html';
EntityChunkCount: 1;
dataChunk: data.
sent := ExternalLong external.
return := HttpServerDLL current
HttpSendHttpResponse: handle
RequestId: request id
Flags: 0
pHttpResponse: response asParameter
pCachePolicy: 0
pBytesSent: sent asParameter
pReserved2: 0
Reserved3: 0
pOverlapped: 0
pLogData: 0.
return = 0 ifFalse: [^self osError: return].
^sent asInteger
Any idea about why if the HttpSendHttpResponse function success and indicates that n bytes has been sent, the client doesn't receive the data?
Thanks, Sebastian
I have figured out the problem. I had an error in the alignment of HTTP_DATA_CHUNK
structure since some fields are 8 bytes aligned so, the data pointer was in a bad offset.
With this fixed, I have tried again with just the HttpSendHttpResponse
without success, and then using both, HttpSendHttpResponse
for the headers and HttpSendHttpResponseEntityBody
for the data, and it works! Maybe the MSDN sample is outdated. There, the data is sent with the response in a single call to HttpSendHttpResponse
.
Thank you very much, Sebastian