views:

247

answers:

1

Is it possible to read an image attachment from System.Net.HttpWebResponse?

I have an url to a java page, which generates images.

When i open the url in firefox, the download dialog appears. Content-type is application/png. Seems to work.

when i try this in c# and make a GET request i retrieve the content-type: text/html and no content-disposition header.

Simple Code:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); HttpWebResponse response = (HttpWebResponse)request.GetResponse();

"response.GetResponseStream()" is empty.

A try with java was succesfull.

Do i have to prepare webrequest or something else?

+2  A: 

You probably need to set a User-Agent header.

Run Fiddler and compare the requests.

SLaks
yep. your right. User-Agent was the problem.
Then you should accept this answer by clicking the hollow check.
SLaks