HTTP Redirection with Indy -Delphi #147

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
g'day I'm Alistair Christie from Lindh Ltd and in this video we're going to look at HTTP redirects so I'm just creating you multi device application and it's going to be blank and what we're going to do is we're going to download this page now this content basically this is easy to work out this is an office ID and basically I've brought some application code to them has this page and scrape the information from it but I had office IDs not the full URL but this redirects automatically to that page so really all we need is this match so this bit is always constant and we can vary the office ID but in this instance we'll only just use the partial URL ignoring this extra bit so I'm gonna use an indie HTTP client and we could use so there's the knit HTTP client and request but I'm gonna use indeed in this instance this is what I happened to choose will throw the page into a memo and with robot non just get the page so often we can just do something like that but this fails to work unfortunately because we get a pages being moved permanently that's a three hour wenzer HTTP redirect which is okay because on the Indy client we can say handle redirects and if we run that again and click the button we get this connection closed gracefully so this is the web server to making the connection it's it's and I'm not exactly sure how it works but I'm not another HTTP protocol expert but basically the Indy client throws a zero if the server terminates the connection at the end so we're gonna do a try except oops try not press our page down and usually now what we need to do is pass in a stream to get requests and I'm just a string stream because its speed yeah nice and simple create it and get rid of this grab the string contents and and yes absolutely I should be using a try finally and buttermilk oh geez I'm lazy so response code is the response code back from the web server and I'm gonna say if it's not 200 we're gonna raise an exception and so and so this get request will fill this stream with the contents of the web page and if it's not successful we raise exception otherwise we check the yum the data the the web page into the memo so hopefully I have time to let correctly and all is good and there's a webpage loop contents and it's quite interesting the the script there's the contents of it they have all this JSON data which basically I managed to extract and then check into a D JSON object and that was nice and easy to pass pass out over all the data which is all the stuff on this this line but anyway I digress however let's go back to here and let's say we now want to download a one of these listings is real estate listings and we have the similarly we have only the ID so if I copy that and paste that in there also automatically redirects us to this page so one might think that for me to download that page I should be able to just do that mr. everything yes and see what happens we go click on a button and eventually we get a not found for a four which is not what we got when we loaded the page in chrome so what's going on now it took me a while to work out what the story was but I'm just gonna throw another memo on so it memo to and make that nice and wide and there is a on redirect event in here with a destination parameter so I'm just gonna add this in and so when the page is redirected we get this event and we can potentially handle odd things which is what happens so we get our not found and the reason we get it as we get this URL which has no we want HTTP colon at the beginning of it why it's not there I'm not sure I suspect the redirection on this website is broken so I'll just copy that we want to add so I'm gonna say if the URL begins with a slash we're gonna add two HTTP on the beginning of it and faintly close that and let's run this again and eventually we get our redirection sorted oh and it gets redirected twice because I should probably put an HTTP yes in there so that's our our first redirection or to fix and then we redirected to the secure site and that's this is pretty much what I wanted to show you India's a very powerful library of components and I use the HTTP component quite often I'm certainly not an expert in it but it generally manages to handle all my needs the I'm bit confused because normally you know me have to throw a SSL hander handler on there to handle this itself but that seemed to work just fine I'm not quite sure why so I can write a note in the comments maybe just being upgraded at some point to support yourself romantically I'm not sure but yeah I'm Alistair Christie from lune deadly Ltd I hope you found this video informative and I'll catch you in the next one
Info
Channel: Alister Christie
Views: 3,106
Rating: 5 out of 5
Keywords: Delphi
Id: vhhDKruC8CA
Channel Id: undefined
Length: 10min 0sec (600 seconds)
Published: Wed Feb 19 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.