[IronPython] Silverlight and Catching HttpWebRequest Errors
Michael Foord
fuzzyman at voidspace.org.uk
Mon May 12 06:41:56 PDT 2008
Michael Foord wrote:
> [snip..]
>> 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")
>>
>> :)
>>
>>
>
> Is that cross-browser?
>
Well, it works on Firefox. Cool.
Michael
> Thanks
>
> Michael
> http://www.ironpythoninaction.com/
>
>
>
>> ~js
>> ________________________________________
>> From: users-bounces at lists.ironpython.com
>> [users-bounces at lists.ironpython.com] On Behalf Of Michael Foord
>> [fuzzyman 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 Foord
>> http://www.ironpythoninaction.com/
>>
>>
>> _______________________________________________
>> Users mailing list
>> Users at lists.ironpython.com
>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>> _______________________________________________
>> Users mailing list
>> Users at lists.ironpython.com
>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>>
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
More information about the Users
mailing list