воскресенье, 14 ноября 2010 г.

Client HTTP Stack: HttpWebRequest and non-ASCII characters in HTTP response headers

Client HTTP Stack in Silverlight seems to bee too strict sometimes. I have an OOB application that uses HttpWebRequest object to get data from external web service.

Unfortunately, HTTP response from the service includes header that contains non-ASCII characters. And it turns out to be a problem. See code snippet below:

void GetResponseCallback(IAsyncResult ar) {
    HttpWebRequest request = (HttpWebRequest)ar.AsyncState;
    WebResponse response = request.EndGetResponse(ar);
    // code continues …
}

EndGetResponse() call results in System.ArgumentException: Specified value has invalid Control characters. Parameter name: value.

I’m not sure whether it is a bug or designed behaviour. But it’s a pity that invalid header prevents application from obtaining response at all. In fact I don’t even need that header, so my workaround was to switch to browser http handling so that I can move on.

And just for the record: the same code works fine in WPF application.

Комментариев нет:

Отправить комментарий

Random thoughts, ideas and questions on .NET development

Постоянные читатели