Mondeo Posted January 16, 2007 Posted January 16, 2007 See this page http://www.dfes.gov.uk/cgi-bin/inyourarea/dist.pl How can I programatically put two postcodes into the form and then submit it so I can parse the HTML response and get the distance? Thanks Quote
MrPaul Posted January 17, 2007 Posted January 17, 2007 HttpWebRequest and HttpWebResponse I recommend the (Http)WebRequest and (Http)WebResponse classes within System.Net. If you look at the source of the web page you will find the names of the two fields - postcode1 and postcode2. You will need to create the POST data for the page, encoded correctly, and then attach it to the request. 'Imports: Imports System.IO Imports System.Net Imports System.Web Public Function GetPostcodeDistance( _ ByVal startPostcode As String, _ ByVal endPostcode As String _ ) As String Const siteUrl As String = "http://www.dfes.gov.uk/cgi-bin/inyourarea/dist.pl" Dim webReq As HttpWebRequest Dim webResp As WebResponse Dim reqStm As StreamWriter Dim respStm As StreamReader Dim postData As String 'Create web request webReq = DirectCast(WebRequest.Create(siteUrl), HttpWebRequest) webReq.Method = "POST" reqStm = New StreamWriter(webReq.GetRequestStream()) 'Write post data to the stream postData = "postcode1=" & HttpUtility.UrlEncode(startPostcode) postData &= "&postcode2=" & HttpUtility.UrlEncode(endPostcode) reqStm.Write(postData) 'Send request and get response webResp = webReq.GetResponse() 'Read from stream respStm = New StreamReader(webResp.GetResponseStream()) 'Parse HTML here End Function Good luck :cool: Quote Never trouble another for what you can do for yourself.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.