[Gambas-user] HttpClient not exposing redirect response codes
PICCORO McKAY Lenz
mckaygerhard at ...626...
Tue Apr 25 22:48:02 CEST 2017
hi lee, in the example, when i debug , the header does not return the
required contents to made the location! i mean i donot test u'r code, but
before send that mail i tested and does not work.. with the specific url..
due that the problem relies on libcurl implementatio of httpclient module
in gambas..
maybe a solution (ugly but proper) its to parse options directly to the
curl implementation
i found some others misctakes/bugs making gambas http/web projects but for
now i must finish my works at job
Lenz McKAY Gerardo (PICCORO)
http://qgqlochekone.blogspot.com
2017-04-25 16:29 GMT-04:00 T Lee Davidson <t.lee.davidson at ...626...>:
> On 04/25/2017 01:36 PM, Benoît Minisini wrote:
> > Le 25/04/2017 à 19:12, T Lee Davidson a écrit :
> >> I have run into a couple of sites that are responding with 301 (Moved
> >> Permanently) and 302 (Moved Temporarily) codes. However, HttpClient.Code
> >> yields "0" for both of those sites/codes (and HttpClient.Reason is
> >> empty). 200 & 404 codes are reported successfully.
> >>
> >> Have I missed something in the properties that is preventing proper
> >> disclosure of redirect response codes?
> >>
> >> Or is this a bug?
> >>
> >> (Project attached.)
> >>
> >
> > HttpClient is "just" libcurl, so it may be a libcurl thing (that library
> > has gazillons of options). I will check...
> >
>
> Thank you for taking the time to check into that, Benoît.
>
> In the meantime, for anyone else needing to loop through redirects
> (currently scanning for a "Location" header), here's a short
> example subroutine:
>
> Private Sub TestPage(sUrl As String)
>
> Dim hClient As New HttpClient
> Dim iMaxRedirects As Integer = 5 'Prevent infinite loop bot trap
> Dim iCurrentRedirects As Integer = 0
> Dim bFound As Boolean
>
> hClient.UserAgent = "AppleWebKit"
> hClient.Async = False
> hClient.URL = sUrl
> hClient.Timeout = 15
> Inc Application.Busy
> Do
> bFound = True 'Reset redirect flag
> hClient.Get
> If hClient.Headers.Find("Location:*", gb.Like) > -1 Then
> bFound = False 'Redirection
> If iCurrentRedirects = iMaxRedirects Then Break
> Inc iCurrentRedirects
> hClient.URL = Replace(hClient.Headers[hClient.Headers.Find("Location:*",
> gb.Like)], "Location: ", "")
> Print hClient.URL
> hClient.Headers.Clear 'Must manually clear headers array or
> "Location" header will persist causing redundant looping
> Endif
> Loop Until bFound = True
> Dec Application.Busy
>
> If hClient.Status < 0 Then
> Print "ERROR"
> End If
>
> Print "Success? -> " & hClient.Code
>
> End
>
>
> ---
> Lee
>
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
More information about the User
mailing list