3

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 \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);

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.

Community
  • 1
  • 1
Mandy
  • 405
  • 2
  • 6
  • 14

1 Answers1

1

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 \r\n, not \n.

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.

Community
  • 1
  • 1
netcoder
  • 66,435
  • 19
  • 125
  • 142