vbs xmlhttp responseText Truncated? - http

Hello all i have a simple vbs script that is grabbing a url(with values using GET) and I need to parse thru the text. However the responsetext i am getting is not the full response. i am getting a string that is 1000 in length however i know the response should be more like 5000.
Function getServer(server_hostname)
Set objHTTP = CreateObject("msxml2.xmlhttp.3.0")
objHTTP.open "GET", "http://someurl/ServerInfo.asp", False
objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
objHTTP.send "B1=GO!!&Server=" + server_hostname
getServer = objHTTP.responseText
End Function
serverStr = getServer(server_hostname)
msgbox(Len(serverStr))
Is there a limitation on how much can be returned? Thank you for your help.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
So i change my function to:
Function getServer(server_hostname)
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
objHTTP.open "GET", "http://someurl/ServerInfo.asp?B1=GO!!&Server=" + server_hostname , False
'objHTTP.setRequestHeader "Content-Type", "text/html"
'objHTTP.send "B1=GO!!&Server=" + server_hostname
objHTTP.send
getServer = objHTTP.responseText
End Function
And now it works...no idea why.

The maximum MsgBox length is 1024 characters.
Ref: http://www.w3schools.com/vbscript/func_msgbox.asp

Related

read all elements from another page using classic ASP

Is there a way to read a another page's elements and grab the whole HTML code?
let's say for example i want to get all the HTML from this page : http://localhost/test3.html
Thank you!
Here's a function I use:
function http_post (strUrl, data)
' call another URL (e.g. ASP or PHP script) via HTTP and POST. "data" should be GET-style parameter string or empty '
dim xmlHttp
Set xmlHttp = Server.Createobject("MSXML2.ServerXMLHTTP.6.0")
With xmlHttp
.Open "POST", strUrl, False
.setRequestHeader "User-Agent", Request.ServerVariables("HTTP_USER_AGENT")
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.setRequestHeader "Content-Length", Len(data)
.Send data
if .Status < 400 then
http_post = .responseText
else
' do error logging here if you want '
http_post = false
end if
.abort()
End With
set xmlHttp = Nothing
end function

Synchronous MSXML2.XMLHTTP producing "The data necessary to complete this operation is not yet available."

In a VBScript, having instantiated:
On Error Resume Next
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
I am doing a sequence of synchronous HTTP PUTs like this:
xmlhttp.open "PUT", TheURL, False
xmlhttp.setRequestHeader "Content-type","application/json"
xmlhttp.setRequestHeader "Accept","application/json"
xmlhttp.send TheXML
If xmlhttp.readyState <> 4 Then
xmlhttp.waitForResponse 1
End If
If xmlhttp.status >= 300 Then
WScript.Echo "Failure: " & TheURL & "<BR>" & TheXML
End If
After a few I check for an error and discover:
-2147483638: The data necessary to complete this operation is not yet available.
Given that I have made these using synchronous calls, how is this possible? How can I avoid this error?
Change this line
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
To
Set xmlhttp = CreateObject("Msxml2.ServerXMLHTTP.6.0")
And add this:
xmlhttp.setTimeouts 15000, 15000, 15000, 15000

Classic ASP Microsoft.XMLHTTP onreadystatechange

I am trying to make an async call with a callback function in classic ASP. This is my code:
Set objHTTP = CreateObject("Microsoft.XMLHTTP")
With objHTTP
.open "POST", base_url_crm & "contacts", True, login_crm, key_crm
.setRequestHeader "Content-Type", "application/json"
.setRequestHeader "Accept", "application/json"
.onreadystatechange = Check_state
.send json
End with
Set objHTTP = Nothing
Public Function Check_state
if objHTTP.ReadyState = 4 then
Response.Write "Finish"
end if
End Function
Its return this error:
Type mismatch: 'onreadystatechange'
How can I execute the Check_state function right after the async call ends?
It must be async (dont wanna make my users wait) and cant do this in javascript.
You cannot bind events to functions like you do in JavaScript because simply passing the name of the function will call it immediately, return its output, and that'll be assigned instead. Use the GetRef function to bind events like so:
Set objHTTP = CreateObject("Microsoft.XMLHTTP")
objHTTP.onreadystatechange = GetRef("Check_state")
See here for documentation on GetRef.
Try using the status instead of onreadystatechange , it returns values ​​such as 200, 404 and 500.

Any Idea Why This HTTP Request is Posting Twice?

When I call the function below, it response writes once as expected (last line of function).
But on the api logger of the website being posted to, it shows two posts. Not only that, but the first post is missing the authentication header.
Would somebody be kind enough to look over this code and tell me if I'm doing anything daft?
private function PostToWebsite(data, url)
Dim httpRequest, postResponse
Set httpRequest = Server.CreateObject("MSXML2.ServerXMLHTTP")
httpRequest.Open "POST", url, False, "un", "pw"
httpRequest.SetRequestHeader "Content-Type", "application/json"
httpRequest.setRequestHeader "Content-Length", len(data)
httpRequest.Send data
if httpRequest.status = 201 then
PostToWebsite = "ok/" & httpRequest.getResponseHeader("Location")
elseif httpRequest.status = 400 then
PostToWebsite= "error/Http 400 error: " & httpRequest.responseText
elseif httpRequest.status = 401 then
PostToWebsite= "error/Http 401 error: " & httpRequest.responseText
else
PostToWebsite= "error/Unknown status in PostToWebsite"
end if
Set httpRequest = nothing
RESPONSE.WRITE PostToWebsite 'this line writes only once
end function
It turns out that there was a comma missing from the JSON payload. Once I fixed that it worked fine.
My new question is: why on earth would that generate a double post, as opposed to a single one that failed?!

classic asp xml receiver page doesn't receive the xml (or so it seems)

I am working on Classic ASP and was going through a possible solution of posting and reading an xml.
I read Tim's reply (which is pasted below) but this doesn't work for me. It seems xmlDoc.load(Request) doesn't load anything. What could be wrong here? I would very much appreciate a prompt response.
This is the posting page:
url = "www.receivingwebsite.com\asp\receivingwebpage.asp"
information = "<Send><UserName>Colt</UserName><PassWord>Taylor</PassWord><Data>100</Data></Send>"
Set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "POST", url, false
xmlhttp.setRequestHeader "Content-Type", "text/xml"
xmlhttp.send information
This is the receiving page:
Dim xmlDoc
Dim userName
set xmlDoc=Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load(Request)
userName = xmlDoc.documentElement.selectSingleNode("UserName").firstChild.nodeValue
Try this :
Dim objXmlRequest
Set objXmlRequest = Server.CreateObject("MSXML2.DOMDOCUMENT.3.0")
objXmlRequest.async = False
objXmlRequest.setProperty "ServerHTTPRequest", True
objXmlRequest.validateOnParse = True
objXmlRequest.preserveWhiteSpace = False
IF objXmlRequest.Load (Request) THEN
''' GET THE REQUEST FROM CLIENT
strQuery = "//" & "ActionName"
Set oNode = objXmlRequest.selectSingleNode(strQuery)
strActionName = oNode.Text
END IF
' The key is in the property set ... check ".setProperty "ServerHTTPRequest", True"
Bye, Martin.

Resources