问题
I have a Windows Phone 7 application that is utilizing the DataServicesClient to access a WCF DataService (ODATA) and I want to ask the service to compress the response.
I know if the Request Headers includes "Accept-Encoding" header with the value of "gzip" the WCF DS will compress the response.
Is there a way to add this header to the Request when using the DataServicesClient on WP7? The Request Headers collection appears to be readonly. What I would like to be able to do is the following (but the Headers property does not have an Add method in this context.)
void entities_SendingRequest(object sender, SendingRequestEventArgs e) { e.Headers.Add("Accept-Encoding", "gzip"); }
- Michael
回答1:
You should be able to modify header collection with following code
private void OnSendingRequest(object sender, System.Data.Services.Client.SendingRequestEventArgs e)
{
e.RequestHeaders["Accept-Encoding"] = "gzip";
}
回答2:
This looks a lot like your other active question ;)
As mentioned on that question, it looks like the ODATA client has no way for you to modify the headers of a request before it is sent, though you could make a feature request.
来源:https://stackoverflow.com/questions/4706535/windows-phone-7-dataservicesclient-request-headers-accept-gzip