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.
昨天,我向php页面询问了有关套接字帖子文件数据的问题。 p> 链接在这里 p>
当我按照方式行事时,我改变了我的代码。 p>
char * str =“ POST /path/upload_file.php HTTP / 1.0
主机: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);
code> pre>
当我执行程序时,可以得到 p>
结果:
501方法未实现
p>
方法未实现
不支持/index.html。
请求中的方法无效 p>
p>
Apache / 1.3.39 localhost端口80的服务器
我想这是可能的:
1。 apache不能支持什么?
(我的apache不支持ssl)
2。 http协议不是细节吗?
3。 其他? p>
非常感谢。 p>
div>
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.