drtkyykai004574380 2010-11-24 03:35
浏览 39
已采纳

socket程序将文件发送到php

Yesterday , I asked a question about socket post file data to php page.

Link is here

Upload and POST file to PHP page

When I follow the way , I changed my code.

char *str="POST /path/upload_file.php HTTP/1.0 
 Host: 00.00.00.00 
   Content-Disposition: name=2.jpg;filename=2.jpg  " ;

write(sockfd, buf, filestat.st_size);
sprintf(send1,"%s%s
",str,buf);
retval= send(sockfd,send1,sizeof(send1),0);

When I execute the Program , can get

result: 501 Method Not Implemented

Method Not Implemented

to /index.html not supported.

Invalid method in request


Apache/1.3.39 Server at localhost Port 80

I guess it's possible : 1. apache can't support something?
(my apache don't support ssl) 2. http protocol is not details? 3. other?

Thanks a lot.

  • 写回答

1条回答 默认 最新

  • dousi6192 2010-11-24 03:44
    关注

    There are multiple issues with your code.

    First, the Host header is part of the HTTP 1.1 specification, and does not apply to HTTP 1.0.

    Second, the delimiter for separating headers as well as body is , not .

    Third, you are using the Content-Disposition in a request, the way it should be used in a response.

    Lastly, you need to send the request as multipart/form-data. The answer you've linked to had it right. The request has to respect that format.

    I've written a detailed example not so long ago (although in PHP, but the request format stays the same). You can find it here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
  • ¥15 win10,这种情况怎么办
  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
  • ¥100 在连接内网VPN时,如何同时保持互联网连接
  • ¥15 MATLAB中使用parfor,矩阵Removal的有效索引在parfor循环中受限制
  • ¥20 Win 10 LTSC 1809版本如何无损提升到20H1版本
  • ¥50 win10 LTSC 虚拟键盘不弹出
  • ¥30 微信小程序请求失败,网页能正常带锁访问
  • ¥15 Matlab求解微分方程,如何用fish2d进行预优?