I found this code through a quick google search (assuming you're using VB.NET):
Apparently that is a working example of an XMLHTTP request with VB. IMO, kind of sloppy code that may be missing a couple of things but gives you an idea of how to use XMLHTTP with Visual Basic.PHP Code:
Dim strResponse, xmlhttp, xmlDom, returnVal
Dim strMessage
Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
xmlhttp.open "POST", "http://mysite.com?environmentId=Development", false
xmlhttp.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.SetRequestHeader "Accept", "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, */*"
xmlhttp.SetRequestHeader "Accept-Language", "en-us"
xmlhttp.SetRequestHeader "Accept-Encoding", "gzip, deflate"
'Send the request synchronously by converting the encoding the message to be sent
xmlhttp.send "message=" & escape(strMessage)
'If the state of the request is 4 then get the response and parse it
If xmlhttp.readyState = 4 Then
'Get the response and set it to a string
strResponse = xmlhttp.responseText
'Create DOM object reference and parse the xml string
Set xmlDom = CreateObject("Msxml2.DOMDocument")
xmlDom.loadxml(strResponse)
'Echo if any error while parsing
If xmlDom.parseerror.errorcode <> 0 Then
Wscript.echo "Reason for the error:" & xmlDom.parseerror.reason
Else
retVal = xmlDom.text
Wscript.echo "Reason for the error:" & retVal
End If
End If
Now here is an example from some code I personally wrote a long time ago that needed to interact with an HTTPS url (this is AutoIt):
That's pretty much the foundation of how to make a web request using XMLHTTP.PHP Code:
Global $oWinHTTP = ObjCreate("Microsoft.XMLHTTP") ; Initialize XMLHTTP object
; Functions
Func _HTTPRequest(ByRef $oWinHTTP, $sMethod, $sURL, $sData = "", $sReferer = "http://google.com")
$oWinHTTP.Open($sMethod, $sURL, False)
$oWinHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5")
;$oWinHTTP.SetRequestHeader("Connection", "keep-alive")
$oWinHTTP.SetRequestHeader("Referer", $sReferer)
If $sMethod == "POST" Then $oWinHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
$oWinHTTP.Send($sData)
Return $oWinHTTP.ResponseText
EndFunc
Example in the context of code (logging into HTTPS url):
Really easy stuff. That's what makes AutoIt/VB great, because they're really simple languages.PHP Code:
Func _Login($sUsername, $sPassword)
Local $sResponse
$sResponse = _HTTPRequest($oWinHTTP, "GET", "https://secure.xgenstudios.com/ballistick/payment.php?username=" & $sUsername & "&key="& _MD5($sPassword) & "&pass=1")
Return StringInStr($sResponse, 'Logged in as')
EndFunc
Hope it helped.
Results 1 to 19 of 19
Threaded View
- 21 Dec. 2014 06:44am #11
Last edited by The Unintelligible; 21 Dec. 2014 at 06:52am.
I'm lightning on my feet