Yesterday , I requested an issue about socket publish file data to php page.

Link is here now

Upload and Publish file to PHP page

After I stick to the way , I transformed my code.

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

write(sockfd, buf, filestat.st_size);
retval= send(sockfd,send1,sizeof(send1),0);

After I execute this program , could possibly 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 suppose it is possible : 1. apache can't support something?
(my apache don't support ssl) 2. http protocol isn't particulars? 3. other?


You will find multiple difficulties with your code.

First, the Host header is area of the HTTP 1.1 specs, and doesn't affect HTTP 1..

Second, the delimiter for separating headers in addition to is \r\n, not \n.

Third, you're while using Content-Disposition inside a request, the actual way it ought to be utilized in an answer.

Lastly, you have to send the request as multipart/form-data. The solution you've associated with been with them right. The request needs to respect that format.

I have written an in depth example not such a long time ago (although in PHP, however the request format stays exactly the same). You are able to think it is here.