Is there a way to get the Content-Type of the response or conversely set the Content-Type of an outgoing request in Silverlight using WebClient?
Edit
I need to make http requests and be able to show progress for them. I want to package the machinery for making the requests into a generic module and use it everywhere in my code. This I have already done. The difficulty seems to be when submitting different types of data to the server in POST I have no way to tell the server what the data is (json,xml,form encode,binary)
I believe I can deal with this by passing ?content-type=x with the request, and setting the server to prefer that over the Content-Type header.
I also have no way to know what kind of content the server responds with, I think I can solve this by passing the expected type of the data when I make a request.
If anyone has a better solution, please speak up :)
/Edit
Here's my predicament. The HttpWebRequest/Response objects implement an internal interface that allows for monitoring the progress of the request. If you want to do large requests it's very important that the user get to see a progress bar showing the status of the download/upload.
So using HttpWebRequest/Response is out. Leaving only WebClient, but I'm finding some odd things about it.
It cannot be subclassed. It's not actually sealed, but the constructor is marked [SecuritySafeCritical], which as far as I can tell, means I can't call it from a derived class. At least I failed, and found others on Google who had failed, but I would be very happy to be proved wrong on this point.
Internally it uses BrowserHttpWebResponse, which does not override the abstract Headers property, and WebClient.ResponseHeaders just forwards to m_Response.Headers, which just throws NotImplementedException.
Not sure Content-Type would even be in ResponseHeaders, but I would have liked to check.
It seems that we have the unhappy choice of having progress info or Content-Type info but not both in Silverlight.
According to the docs, there also seems no way to set Content-Type on the outgoing request either with WebClient. Content-Type is listed as a restricted header. I haven't actually tested this though.
Although it's interesting to note that on an error, you actually get passed the response object and have access to StatusCode, Content-Type, etc.