【问题标题】:HttpSendHttpResponse no data sentHttpSendHttpResponse 没有数据发送
【发布时间】:2015-02-03 17:04:16
【问题描述】:

我正在使用Ms http server api v2(同步模式)实现一个网络服务器,我正在尝试从网络浏览器对其进行测试。

我从浏览器向http://localhost:50000/uri/ 发送了一个GET 请求,我的应用程序正确地接收到了它。然后我发送响应,使用HttpSendHttpResponse 在 (HTTP_DATA_CHUNK) 中包含一些数据,并发送了 131 个字节。但是,浏览器没有收到任何数据。 我也用wininet客户端测试过,结果相同。

这是我的发送响应代码(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 

知道为什么如果 HttpSendHttpResponse 函数成功并指示已发送 n 个字节,客户端没有收到数据吗?

谢谢, 塞巴斯蒂安

【问题讨论】:

  • 如果你不知道你不会在浏览器中看到这个(在网络检查器之外),因为HttpSendHttpResponse 用于 HTTP 标头,HttpSendResponseEntityBody 用于数据
  • 谢谢@AlexK.,我知道HttpSendHttpResponse 也可以一键发送数据。我正在关注 MSDN 示例 [msdn.microsoft.com/en-us/library/windows/desktop/…,在那里,使用HttpSendHttpResponse 在数据块缓冲区中发送一些文本作为答案。无论如何,我会尝试致电HttpSendResponseEntityBody。
  • 我不知道它可以做到这一点,MSDN "Remarks" 说 “HttpSendHttpResponse 函数用于创建和发送响应头,HttpSendResponseEntityBody 函数可用于发送实体-根据需要提供正文数据。”
  • 使用 HttpSendHttpResponse 没有数据和 Flags = HTTP_SEND_RESPONSE_FLAG_MORE_DATA 然后使用数据和 Flags = HTTP_SEND_RESPONSE_FLAG_DISCONNECT 调用 HttpSendResponseEntityBody 的结果相同。浏览器显示一个空白页面。

标签: http winapi smalltalk httpserver


【解决方案1】:

我已经找到了问题所在。我在对齐HTTP_DATA_CHUNK 结构时出错,因为某些字段是 8 字节对齐的,因此数据指针的偏移量错误。 修复此问题后,我再次尝试仅使用HttpSendHttpResponse,但没有成功,然后将HttpSendHttpResponse 用于标头,HttpSendHttpResponseEntityBody 用于数据,它可以工作!也许MSDN sample 已经过时了。在那里,数据与响应一起发送到HttpSendHttpResponse。

非常感谢你,塞巴斯蒂安

【讨论】:

    猜你喜欢
    • 2013-11-24
    • 2014-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-12
    • 1970-01-01
    相关资源
    最近更新 更多