Could some one help me to get output from the following http request. In normal browser i am getting a webpage when this url is entered. But when i post a request from httpsocket i am getting a different result page with error. the url is “http://connect2.kw.zain.com/smartpay/smartpay.smart?payment=post&order=99745051,3”
Help us help you. Show us the code you are trying to use. Be sure to anonymize any keys.
Dim h As New HTTPSocket
Dim content As String
content = h.Get (“http://connect2.kw.zain.com/smartpay/smartpay.smart?payment=post&order=99745051,3”, 0)
Above is the code i am using and i get some value in the content string. That is an error page. But if i put the url in a browser i am getting a webpage which i am not getting using httpsocket
Might me worth trying to follow the page using fiddler2. There is something going on there where it is not recognizing the socket as a legitimate browser.
It might be detecting your socket as a robot. You could try setting the User-agent, Referer, etc, with SetRequestHeader (just look at your own browser headers to see what might help to fake it). Some sites also execute a little bit of Javascript to detect robots, which of course won’t be executed by your socket. If that’s the case then it gets a bit trickier…
[quote=163976:@S Abraham]Dim h As New HTTPSocket
Dim content As String
content = h.Get (“http://connect2.kw.zain.com/smartpay/smartpay.smart?payment=post&order=99745051,3”, 0)
Above is the code i am using and i get some value in the content string. That is an error page. But if i put the url in a browser i am getting a webpage which i am not getting using httpsocket[/quote]
Try Perhaps:
Dim URLBase as String = "http://connect2.kw.zain.com/smartpay/smartpay.smart?"
Dim ContentURL as String = EncodeURLComponent("payment=post&order=99745051,3"
Dim URLtoUse as String = URLBase + ContentURL
content = h.Get (URLtoUse, 10)
Also I would set your UserAgent parms. I usually set this in the HTTPSecure/HTTP Class’ Constructor. Not sure if you are Mac but this is what I use for mine.
Self.SetRequestHeader("Accept", "*/*")
Self.SetRequestHeader("Accept-Encoding:","gzip,deflate,sdch")
Self.SetRequestHeader("User-Agent:","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.101 Safari/537.36")
Self.SetRequestHeader("Connection", "keep-alive")
Self.SetRequestHeader("Accept-Language", "en-US,en;q=0.8")
HTH
Mike wouldn’t that encode the ampersand (which would not pass the variables) ?
Ha Yes you are right Tim. Thats what I get for writing code straight into here
Dim URLBase as String = "QuickPay - QuickPay - Zain Kuwait
Dim ContentURL1 as String = EncodeURLComponent(“payment=post”)
Dim ContentURL2 as String = “&”
Dim ContentURL3 as String = EncodeURLComponent(“order=99745051,3”)
Dim URLtoUse as String = URLBase + ContentURL1 + ContentURL2 + ContentURL3
content = h.Get (URLtoUse, 10)
Also:
http://documentation.xojo.com/index.php/EncodeURLComponent
Its working when i add the UserAgent header. But now when i press the submit button inside the page its again fails with error. but if i press it from a normal browser it goes to another page. when i analysed it with fiddler there is few needed headers(eg: Referer) missing when submitting it through HTMLViewer. Any idea