Last post Oct 15, 2009 12:32 PM by randallt
Oct 13, 2009 11:07 AM|johnsheehan|LINK
Services like S3 heavily rely on the value of the "Host" http header, but when I set that value in DefaultHeaders I get an exception thrown when the request is executed (the exception text just says "Host"). Same with the Date header. Is there a supported
way to set these headers that I'm missing?
Oct 14, 2009 11:57 AM|randallt|LINK
I assume you are using the HttpClient and trying to set the "Host" header. Is that correct?
Under the covers, HttpClient is using the HttpWebRequest, which doesn't allow you to set the Host header. However, this shouldn't be a problem for you because it will set the Host header based on the host in URI of the request. See
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx for more details.
Do you have a need to set the host header to some value other than what is in the URI of the request?
Oct 15, 2009 01:19 AM|johnsheehan|LINK
Your assumptions are correct. My apologies for leaving out the detail. In the case of s3, all the requests are made to s3.amazonaws.com but you set which bucket you want to act on with the Host header, which for all bucket operations is different than the
host used for the request.
Oct 15, 2009 12:32 PM|randallt|LINK
I'm not an expert on S3, but looking at the documentation quickly I believe that you still include the bucket name in the request URI, and therefore, the host header would get set correctly by the HttpClient.
Looking at the s3 documentation at:
http://docs.amazonwebservices.com/AmazonS3/2006-03-01/dev/index.html?UsingBucket.html. It says:
"The similarities between buckets and domain names is not a coincidence—there is a direct mapping between Amazon S3 buckets and subdomains of s3.amazonaws.com. Objects stored in Amazon S3 are addressable using the REST
API under the domain bucketname.s3.amazonaws.com. For example, if the object
homepage.html is stored in the Amazon S3 bucket
mybucket its address would be http://mybucket.s3.amazonaws.com/homepage.html."