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.

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

报告相同问题?

悬赏问题

  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计