New topic: HTTPSocket help.
<http://forums.realsoftware.com/viewtopic.php?t=46992> Page 1 of 1 [ 5 posts ] Previous topic | Next topic Author Message waveuponwave Post subject: HTTPSocket help.Posted: Mon Feb 18, 2013 7:21 pm Joined: Fri Jan 29, 2010 12:39 pm Posts: 874 Location: Virginia, USA Currently I'm using this code to retrieve the source code from a URL. Dim Socket1 As New HTTPSecureSocket s = Socket1.Get(txtURL.Text, 0) TextArea1.Text = s It seems to work better as a secure socket. However sometimes I still don't get the source or I get source code with a message saying the page has moved. Is there a reliable way to get the source code from a URL? What am I doing wrong? Thanks. _________________ RS 2011 r4 Enterprise on Win 7 Top charonn0 Post subject: Re: HTTPSocket help.Posted: Mon Feb 18, 2013 8:07 pm Joined: Mon Apr 02, 2007 2:08 am Posts: 1127 Location: San Francisco, CA, USA The problem is that you're assuming that each request will succeed (HTTP status 200) and not handling cases where errors (e.g. 404 Not Found) or redirection (e.g. 302 Found) occur. e.g. something like this in the HTTPSocket's HeadersReceived event: Sub HeadersReceived(headers as internetHeaders, httpStatus as integer) Select Case httpStatus Case 301, 302 'Redirect Dim newURL As String = headers.CommaSeparatedValues("Location") If newURL <> "" Then Me.Get(newURL) End If Case 404 'Not found! 'handle the error Case 200 '200 OK, so do nothing Return Else 'any other httpStatus Raise New RuntimeException End Select End Sub _________________ Boredom Software Top waveuponwave Post subject: Re: HTTPSocket help.Posted: Mon Feb 18, 2013 8:08 pm Joined: Fri Jan 29, 2010 12:39 pm Posts: 874 Location: Virginia, USA Thanks for the reply. I will give that a try. _________________ RS 2011 r4 Enterprise on Win 7 Top waveuponwave Post subject: Re: HTTPSocket help.Posted: Mon Feb 18, 2013 8:58 pm Joined: Fri Jan 29, 2010 12:39 pm Posts: 874 Location: Virginia, USA Ok so that helped, I was being redirected to the same link but with https instead of http. However it gets stuck in a loop there redirecting over and over. How do I handle this event to get the source from the https redirect? Thanks! _________________ RS 2011 r4 Enterprise on Win 7 Top waveuponwave Post subject: Re: HTTPSocket help.Posted: Mon Feb 18, 2013 9:05 pm Joined: Fri Jan 29, 2010 12:39 pm Posts: 874 Location: Virginia, USA Nevermind I added an HTTPSecureSocket and had the first socket redirect to the secure socket. Now it works! Thanks for the help! _________________ RS 2011 r4 Enterprise on Win 7 Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 5 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
