0

I can download a test.pdf file using this get command below with a code that I've in C for a microcontroller to communicate with a server:

GET /TestFolder/test.pdf HTTP/1.1\r\n Host: www.xyz.com\r\n\r\n the file: test.pdf is located in folder: TestFolder at Host: xyz.com

I wanted to test the program on Amazon S3; so I created an account and uploaded the data and made the file and folder public, added policy to the S3 bucket so objects can be accessed. When I send the GET command above to the S3 host: s3-us-west-2.amazonaws.com I get an error after the socket is connected and I get the server's IP, error message from S3 says:

Response error: HTTP/1.1 400 Bad Request
Transfer-Encoding: chunked
Date: Mon, .. 2015 04:15:02 GMT
Connection: close
Server: AmazonS3

I thought to remove extra \r\n from the get command, and sent this command to s3 GET /TestFolder/test.pdf HTTP/1.1\r\n Host: s3-us-west-2.amazonaws.com\r\n

This time, the requests hangs with no response. I don't get any error message, the socket is connected as usual and I see the server's IP.

I'll appreciate any suggestion or input where the problem could be. Obviously the GET command works for file download when the file is public at other sites, has anyone encountered this kind of issue with http/1.1 GET command? I can access the file from AWS S3 in my browser by typing the link.

ASG
  • 39
  • 1
  • 4

1 Answers1

0

You need \r\n twice at the end of the request, otherwise the server thinks it's waiting for more headers. The problem, here, is that you are not specifying the bucket, which you can do in the path or in the Host: header... you have to do it in one, or the other, but not both.

GET /your-bucket-name/TestFolder/test.pdf HTTP/1.1\r\n
Host: s3-us-west-2.amazonaws.com\r\n\r\n

...or...

GET /TestFolder/test.pdf HTTP/1.1\r\n
Host: your-bucket-name.s3-us-west-2.amazonaws.com\r\n\r\n
Michael - sqlbot
  • 169,571
  • 25
  • 353
  • 427
  • Thanks Michael. Name of my bucket is TestFolder, For some reason it still does not work. GET /TestFolder/test.pdf HTTP/1.1\r\n Host: s3-us-west-2.amazonaws.com\r\n\r\n – ASG Feb 22 '15 at 00:48
  • I get the response as below for the command: Response error: HTTP/1.1 400 Bad Request Transfer-Encoding: chunked – ASG Feb 22 '15 at 02:01