Problem with missing data when using the .net Webclient and POST method

blandie

Newcomer
Joined
Aug 10, 2004
Messages
5
Hi All,

I am trying to create a simple program that mimicks a web broswer submitting details to a flight search engine.

The real webpage works by submitting the Form data via the POST command to an .asp url, I have attmepted to replicate this by using the Webclient and NameValue collection to submit the form data from my .Net application.

However although the POST meth works fine no Form data is actually submitted to the search engine.

I have use an HTTP monitor to inspect the HTTP Request headers and there is a difference between the two POSTs, although the Content-Length is the same so I belive the data is being picked up from my application.

HTTP Request Header From Working Broswer
----- Hypertext Transfer Protocol -----
HTTP: POST /en/book/step2.asp HTTP/1.1
HTTP: Content-Type: application/x-www-form-urlencoded
HTTP: User-Agent: Easyjet
HTTP: Host: www.easyjet.co.uk
HTTP: Content-Length: 118
HTTP: Cache-Control: no-cache
HTTP: Cookie: lang2002=en
HTTP: Data

HTTP Request Header From Non-Working .Net App
HTTP: POST /en/book/step2.asp HTTP/1.1
HTTP: Content-Type: application/x-www-form-urlencoded
HTTP: User-Agent: Easyjet
HTTP: Host: www.easyjet.co.uk
HTTP: Content-Length: 118
HTTP: Cache-Control: no-cache
HTTP: Cookie: lang2002=en

Notice the missing HTTP: Data This is containing the form data.

Below is an extract of the code I am trying to use:

Code:
     Dim WebClient As New System.Net.WebClient

        WebClient.Headers.Add("User-Agent", "Easyjet")
        WebClient.Headers.Add("Cache-Control", "no-cache")
        WebClient.Headers.Add("Cookie", "lang2002=en")

        Dim ParamColl As New System.Collections.Specialized.NameValueCollection
        ParamColl.Add("orig", "LDN")
        ParamColl.Add("dest", "ACL")
        ParamColl.Add("oDay", "18")
        ParamColl.Add("oMonYear", "082004")
        ParamColl.Add("rDay", "00")
        ParamColl.Add("rMonYear", "000000")
        ParamColl.Add("numOfAdults", "1")
        ParamColl.Add("numOfKids", "0")
        ParamColl.Add("numOfInfants", "0")
        ParamColl.Add("numOfPax", "1")

        Try
            Dim WebClientResponse As Byte()
            WebClientResponse = WebClient.UploadValues("http://www.easyjet.co.uk/en/book/step2.asp", "POST", ParamColl)
            Debug.Write(System.Text.Encoding.ASCII.GetString(WebClientResponse))
        Catch ex As Exception
            Debug.Write(ex.Message)
        End Try

Thanks for any help you folks can provide on this, I am a little bit of a .Net noob so go easy ;-p

Cheers, Peter :confused:
 
Figured it out, it wasnt anything to do with the POST but the data it contained. The following namevalue pairs were incorrect and so the server was re-directing.

ParamColl.Add("dest", "ACL")
ParamColl.Add("rMonYear", "000000")

Regards, Peter
 
Back
Top