打印
[嵌入式linux]

HTTP-POST方法内容长度过大,多次发送的问题

[复制链接]
1350|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
jolee|  楼主 | 2013-7-25 11:19 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
POS, ST, TI, IO, TE
没找到合适分类发帖区,暂借宝地,谢谢!
------------------------
请教HTTP-POST方法使用时,当要上传内容长度Content-Length超过IP包长度限制如10000,一般是如何处理的?
{
  "POST /ems/php/emud.php HTTP/1.0\r\n"
  "Host: 192.168.52.69\r\n"
  "Connection: close\r\n"
  "Content-Type: application/x-www-form-urlencoded\r\n"
  "Content-Length: 10000\r\n"
  "\r\n"
  "information=xxxxxxxxxxxxxxxxx"
};

可以把要发送的内容拆分成:头字符串/数据内容/数据内容/数据内容... 再多次调用send()发送出去,发送完所有数据再close(),这样可行吗?发送头字符串时,Connection: 是否要定义为Keep-Alive?

感谢!

相关帖子

沙发
maztower| | 2013-8-5 10:39 | 只看该作者
调用send后,实际发送的数据量不一定等于设定的数据长度,原因是网络拥塞,缓冲区满或其他异常
实现一个safesend函数,如下
int SafeSend(SOCKET sock, Uint8* pBuf, int nLen)
{
        int nRet = 0;
        int nSended = 0;
        int ntry = 0;
        while (nSended < nLen) {
                nRet = send(sock, pBuf + nSended, nLen - nSended, 0);
                if (nRet <= 0) {
                        if (ntry < 5) {
                                TSK_sleep(1);
                                ntry++;
                                continue;
                        }else {
                                break;
                        }
                }
                ntry = 0;
                nSended += nRet;
        }
       
        if (nSended < nLen) {
                return -1;
        }
        return nSended;
}

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

5

主题

11

帖子

0

粉丝