gpt4 book ai didi

php - 套接字程序将文件发布到php

转载 作者:搜寻专家 更新时间:2023-10-31 21:45:38 24 4
gpt4 key购买 nike

昨天,我问了一个关于socket post file data to php page的问题。

链接在这里

Upload and POST file to PHP page

按照我的方法,我更改了我的代码。

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

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

当我执行程序时,可以得到

结果:501 方法未实现

方法未实现

不支持/index.html。

请求中的方法无效


Apache/1.3.39 服务器在 localhost 端口 80

我想这是可能的:1. apache不能支持什么?
(我的apache不支持ssl)2.http协议(protocol)没有详细说明?3.其他?

非常感谢。

最佳答案

您的代码存在多个问题。

首先,Host header 是 HTTP 1.1 规范的一部分,不适用于 HTTP 1.0。

其次,headers和body的分隔符是\r\n,不是\n

第三,您在请求中使用了 Content-Disposition,它应该在响应中使用。

最后,您需要将请求作为multipart/form-data 发送。您链接到的答案是正确的。请求必须遵守该格式。

不久前我写了一个详细的例子(虽然是用PHP,但是请求格式保持不变)。你可以find it here .

关于php - 套接字程序将文件发布到php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4263249/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com