Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Problem with getting info from site using POST method in VBScript

$
0
0

Hello, dear collegues! I need your help again.

Fisrt of all, this is NOT ad. I try to make a POST request on website of railway ticketshttp://booking.uz.gov.ua/en/ to know if there is tickets on current date. BUT... have a problem. I'm using a VBScript to make a request. To know what HTTP Header and POST request to send on website I used Firebug (Mozilla Addon). Here is a screen of Firebug.

Brilliant. I get response in a form of JSON. I'm almoast happy. BUT...I can't repeat it with script. I get empty TXT file if I use URL = http://booking.uz.gov.ua/en/purchase/search/  to send a request. If I use http://booking.uz.gov.ua/i/js/common.138.js - path to script that fairbug show me (on screen, right side, red pointer) - URL to send a request, I just receive a contents of common.138.js in my TXT file. But I expect to receive info in JSON type like on screen above in sectionResponse that fairbug shows. 

That's my script. 

Dim URL
Dim Request
set objHTTP = CreateObject("Microsoft.XMLHTTP")
URL = "http://booking.uz.gov.ua/en/purchase/search/"
'or URL = "http://booking.uz.gov.ua/i/js/common.138.js" - that fairbug shows
'sRequest - I get it too from fairbug, this is ID of stations, and name of stations encrypted.
sRequest = "station_id_from=2200001&station_id_till=2208001&station_from=Kyiv&station_till=Odesa&date_dep=08.18.2013&time_dep=00%3A00&search="
'Call of function
objHTTP= HTTPPost(Url, Request)

  Function HTTPPost(Url, sRequest)
   set objHTTP = CreateObject("Microsoft.XMLHTTP")
    objHTTP.open "POST", URL, false
    ' HTTP Headers I simply took from fairbug too.
    objHTTP.setRequestHeader "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
    objHTTP.setRequestHeader "Accept-Encoding", "gzip, deflate"
    objHTTP.setRequestHeader "Accept-Language", "en-US,en;q=0.5"
    objHTTP.setRequestHeader "Content-Length", "Len(Request)"
    objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"
    objHTTP.setRequestHeader "GV-Ajax", "1"
    objHTTP.setRequestHeader "GV-Unique-Host", "1"
    objHTTP.setRequestHeader "Host", "booking.uz.gov.ua"
    objHTTP.setRequestHeader "Referer", "http://booking.uz.gov.ua/en/"
    objHTTP.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0"
    objHTTP.send Request
    HTTPPost =  objHttp.responseText
   'Here I write response to a txt file.
   Set FSO = CreateObject("Scripting.FileSystemObject")
   Set oFile = FSO.OpenTextFile("D:\Results.txt", 2, True)
   oFile.Write(objHttp.responseText)
   oFile.Close
   Set oFile = Nothing
   Set FSO = Nothing
  End Function

What I noticed, if refresh the website, and try to resend a request, fairbug give me an error:

NetworkError: 400 Bad Request - http://booking.uz.gov.ua/en/purchase/search/"

More, I can't to simply write name of station, I need to chose it from drop-down list. OR I get an error.

Maybe it's some kind of defence from people like me??? There is a way to make my script work????

I don't know how to solve this problem. Help me please. Can't sleep. Can't eat. Thanks very very much.




Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>