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
Invalid method in request
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.
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.