[IronPython] Silverlight and Catching HttpWebRequest Errors

Michael Foord fuzzyman at gmail.com
Wed May 14 22:48:46 CEST 2008

On May 12, 9:17 am, Jimmy Schementi <Jimmy.Scheme... at microsoft.com>
> The actual type returned by HttpWebRequest.Create() is a BrowserHttpWebRequest, but it's internal (not sure why). Anyway, it has a ProgressFailed event you can hook.

Hello Jimmy,

As far as I can tell it *doesn't* have the 'ProgressFailed' event.

I need to make cross-domain POST, and although the request gets made
successfully I'm getting a COM Arg Exception everytime (I think
because the server is slow to respond). This is screwing me at the

FYI - when I execute the following code in Silverlight:

  from System.Net import WebRequest
  from System import Uri

  u = Uri('http://www.v.com')
  req = WebRequest.Create(u)
  print req.ProgressFailed

I get the following exception:

Traceback (most recent call last):
  File "None", line 6, in <undefined>
AttributeError: 'BrowserHttpWebRequest' object has no attribute

All the best,

Michael Foord

> PS. If you REALLY want synchronous downloading, just hack on XMLHttpRequest
> def download(url):
>     request = HtmlPage.Window.CreateInstance("XMLHttpRequest")
>     request.Invoke("open", "GET", url, false) # false means synchronous
>     request.Invoke("send", "")
>     return request.GetProperty("responseText")
> :)
> ~js
> ________________________________________
> From: users-boun... at lists.ironpython.com [users-boun... at lists.ironpython.com] On Behalf Of Michael Foord [fuzzy... at voidspace.org.uk]
> Sent: Monday, May 12, 2008 12:58 AM
> To: Discussion of IronPython
> Subject: [IronPython] Silverlight and Catching HttpWebRequest Errors
> Hello guys,
> I have a problem with catching network errors raised by HttpWebRequest
> in Silverlight. (Not necessarily an IronPython specific question - but
> you guys are so intelligent you are always the first place I turn...)
> HttpWebRequest uses an async model for fetching resources. If there is a
> problem (triggered usually by a slow response from the server), then it
> can happen *after* I have made the request - but before my callback is
> invoked. This gives me nowhere to catch the exception, as effectively it
> happens 'inside Silverlight'. I wondered if there was a solution... ?
> def callback(asyncResult):
>     ...
> uri = Uri(some_url)
> req = HttpWebRequest.Create(uri)
> req.BeginGetResponse(AsyncCallback(callback), object())
> The error occurs after BeginGetResponse, but before calback. Any ideas
> for catching it?
> Michael Foordhttp://www.ironpythoninaction.com/
> _______________________________________________
> Users mailing list
> Us... at lists.ironpython.comhttp://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> _______________________________________________
> Users mailing list
> Us... at lists.ironpython.comhttp://lists.ironpython.com/listinfo.cgi/users-ironpython.com

More information about the Ironpython-users mailing list