vbscript/asp msxml.xmlhttp.6.0 Error Only on First Try - asp-classic

I have asp/vbscript code that posts an XML body to a web api, and received back an XML response.
In a browser, (new session) on the first load, it errors out, and this is the message:
err.source = msxml6.dll, err.number = -2146697208 - The download of the specified resource has failed.
On reloading the page, it works, and it works every single time after that until the session times out.
What could be happening here?
The Code is below - fairly standard.
Dim oXmlHttp : Set oXmlHttp = CreateObject("MSXML2.XMLHTTP.6.0")
On Error Resume Next
oXmlHttp.Open "POST", sUri, False
oXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
oXmlHttp.Send(sRequest)
If Err Then
response.write "err.source = " & err.Source & ", err.number = " & err.number & " - [" & err.Description & "]"
End If
On Error Goto 0

The first thing you should do is stop using XMLHTTP and use ServerXMLHTTP instead. The XMLHTTP is not safe for use in the server context.

Related

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

Error in Classic ASP page while reading rss feed

We have an old application developed in classic ASP and today it is generating an error while consuming RSS feed. After through investigating(tried to wrote code in .NET to get detailed error) found its special character, in generated output which is causing trouble. When you run RSS feed in browser and run generated XML from local server, it works fine.
Error: System error: -2147012866.
Line: 0
Text:
I have no idea how to fix it.
<%
Dim objXML
Dim objItemList
Dim objItem
Dim I
Set objXML = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
objXML.async = False
I = 0
objXML.setProperty "ServerHTTPSRequest", True
'objXML.Load(Server.MapPath("abcd.xml"))
objXML.Load("http://search.jobs.wa.gov.au/wagov.rss?agencyID=925")
If objXML.parseError.errorCode <> 0 Then
Response.Write "<pre>" & vbCrLf
Response.Write "<strong>Error:</strong> " & objXML.parseError.reason
Response.Write "<strong>Line:</strong> " & objXML.parseError.line & vbCrLf
Response.Write "<strong>Text:</strong> " & Server.HTMLEncode(objXML.parseError.srcText) & vbCrLf
Response.Write "</pre>" & vbCrLf
End If
%>
Zam,
Even if you correct it from ServerHTTPSRequest to ServerHTTPRequest in SetProperty, still nothing works.
As mentioned in question, it also worked fine when you use saved the XML file(generated from RSS FEED)
Also, if you look into below post, it states that it's all because of encoding="iso-8859-1" which is also the case for above issue.
http://stackoverflow.com/questions/4332828/vbscript-tries-to-read-rss-feeds-have-issue-of-system-does-not-support-the-speci
but solution provided there causes another error that The connection with the server was terminated abnormally
I believe error in objXML.SetProperty "ServerHTTPSRequest", True
Because
Error description: Property name is invalid.

Is it possible to copy files from a UNC source to a webDav destination with a script?

I work in a very large, complex Intranet environment. I have run into a very unique issue that I cannot seem to resolve.
Forwarning
The technologies I mention are very outdated and that is the way is has to stay. I work in a very large enterprise and they have a ton of legacy things in place. I normally work on the modern side of things, but this got placed in my lap.
The problem:
We have a file located on our IIS 7.x server with path \serverName\shareName\wwwroot\myfile.jpg. I need to copy this file to a webDav location of a DIFFERENT web server using ASP , vbscript, or another similar web technology. For a multitude of security implications, I don't have access to the webDav UNC path, only the http: path. I am able to map this drive and access the http: location using windows explorer. I can even manually copy files, create files, and delete them. However, when I try to use a script, I get no where.
I am not great with vbscript so bare with my attempts:
Attempt 1:
Set oShell = CreateObject("WScript.Shell")
strCommand = oShell.Run("Xcopy ""sourceLocation"" ""destination location"" /S /Y", 0, True)
If strCommand <> 0 Then
MsgBox "File Copy Error: " & strCommand
Else
MsgBox "Done"
End If
Attempt 2:
<%
dim objFSOpublish
set objFSOpublish = CreateObject("Scripting.FileSystemObject")
strCurrentUNCfull = "sourcePath"
mPublishPath = "destinationPath"
objFSOpublish.CopyFile strCurrentUNCfull, mPublishPath
set objFSOpublish = nothing
%>
I have no idea if this is even possible to do without the webDav UNC path because I don't have much experience with webDav. If it is possible I have exhausted my limited knowledge in this space and need help badly. I scoured Google tirelessly trying to find a similar issue to no avail. Any and all help or direction will be greatly appreciated.
You're going to want to do something like this:
On Error Resume Next
sUrl = "YourURLHere"
sFile = "UNCPathToYourFile"
'Here we are just reading your file into an ODB
'stream so we can manipulate it
Set oStream = CreateObject("ADODB.Stream")
oStream.Mode = 3
oStream.Type = 1
oStream.Open
oStream.LoadFromFile(sFile)
'Here we are doing the upload of the oStream
'object we just created.
Set oHTTP = CreateObject("MSXML2.ServerXMLHTTP")
oHTTP.Open "POST", sUrl, False
oHTTP.SetRequestHeader "Content-Length", oStream.Size
oHTTP.Send oStream.Read(oStream.Size)
'Check for errors.
If Err = 0 Then
Wscript.Echo oHTTP.responseText
Else
Wscript.Echo "Upload Error!" & vbCrLf & Err.Description
End If
'Optionally close out our objects
oStream.Close
Set oStream = Nothing
Set oHTTP = Nothing
Here is the code I am currently using with the actual file path redacted. Let me know if you see anything that is incorrect.
The page is saved as a .ASP.
<%
sUrl = "http://server.site.com:80/subDomain/wwwroot/"
sFile = "\\server\developmentShare\wwwroot\page.htm"
'Here we are just reading your file into an ODB
'stream so we can manipulate it
Set oStream = Server.CreateObject("ADODB.Stream")
oStream.Mode = 3
oStream.Type = 1
oStream.Open
oStream.LoadFromFile(sFile)
'Here we are doing the upload of the oStream
'object we just created.
Set oHTTP = CreateObject("MSXML2.ServerXMLHTTP")
oHTTP.Open "POST", sUrl, False
oHTTP.SetRequestHeader "Content-Length", oStream.Size
oHTTP.Send oStream.Read(oStream.Size)
'Check for errors.
If Err = 0 Then
Wscript.Echo oHTTP.responseText
Else
Wscript.Echo "Upload Error!" & vbCrLf & Err.Description
End If
'Optionally close out our objects
oStream.Close
Set oStream = Nothing
Set oHTTP = Nothing
%>

IPN is now disabled Need help deciphering the asp code

Paypal has been sending emails warning IPN is failing.
I've not made any changes to my code, and it is really old code.... has been working for 5+ years.... been so long that I've had to do anything on this site.
I searched the server logs for more information... this is what I found repeatedly
|35|80040e14|Syntax_error_(missing_operator)_in_query_expression_'OrderID='.
I checked the code on the ipn page of the site, and I'm stumped.
Nothing is changed but it stopped working
This is line 34 thru 36 of the code of the ipn page:
MM_Cmd.CommandText = "UPDATE Orders SET txn_id='" & txn_id & "',payment_status='" & payment_status & "' WHERE OrderID=" & Item_number
MM_Cmd.Execute
end function
UPDATE:
Here is the full code that shows Item_number:
<%
str = Request.Form & "&cmd=_notify-validate"
' post back to PayPal system to validate
set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
objHttp.open "POST", "https://www.paypal.com/cgi-bin/webscr", false
objHttp.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
objHttp.Send str
' assign posted variables to local variables
Item_number = Request("item_number")
Payment_status = Request("payment_status")
Txn_id = Request("txn_id")
if (objHttp.status <> 200 ) then
' HTTP error handling
elseif (objHttp.responseText = "VERIFIED") then
if Payment_status = "Completed" then 'only update database if the response text is verified and the payment complete
UpdateOrder
end if
elseif (objHttp.responseText = "INVALID") then
' log for manual investigation
else
' error
end if
set objHttp = nothing
function UpdateOrder
'on error resume next
Set MM_Cmd = Server.CreateObject("ADODB.Command")
MM_Cmd.ActiveConnection = MM_CharonCart_STRING
MM_Cmd.CommandText = "UPDATE Orders SET txn_id='" & txn_id & "',payment_status='" & payment_status & "' WHERE OrderID=" & Item_number
MM_Cmd.Execute
end function
%>
The problem is with your variable Item_number. There's a small chance that if you rewrite the end of your query as
... where OrderID=" & Cint(Item_number)
then you will solve your problem, however you probably need to look at the code which assigns a value to Item_number

How to properly report / handle classic asp page errors and database errors

I have been trying to create an error handling path for our classic asp website. I have been searching for information for 3hrs now and have not found much even here on stack overflow. So if you can point me towards a duplicate great ... I couldn't find anything although it must exist.
My plan is the following ...
Have proper error handling in the stored procedures. Any errors that occur get inserted into an error table and are also raised back up to the application.
Have "On error resume next" set on the page. Then check the connection.errors collection for errors. As well as Server.GetLastError() property.
If there are any redirect to a page to to display safe error information and insert another record into another database table to tie the page name where the error occurred to the already existing database error in the database table mentioned above for later debugging purposes.
I have created the following page to to begin testing this out. However it is not working.
Dim cmd
Set cmd = Server.CreateObject("ADODB.Command")
cmd.ActiveConnection = con
cmd.CommandType = adCmdStoredProc
on error resume next
cmd.CommandText = "spReturnDBException"
cmd.CommandTimeout = 30 ' 2 minutes
cmd.Execute
dim objErr
set objErr = Server.GetLastError()
if objError.ASPCode <> 0 then
response.write("ASPCode=" & objErr.ASPCode)
response.write("")
response.write("ASPDescription=" & objErr.ASPDescription)
response.write("")
response.write("Category=" & objErr.Category)
response.write("")
response.write("Column=" & objErr.Column)
response.write("")
response.write("Description=" & objErr.Description)
response.write("")
response.write("File=" & objErr.File)
response.write("")
response.write("Line=" & objErr.Line)
response.write("")
response.write("Number=" & objErr.Number)
response.write("")
response.write("Source=" & objErr.Source)
else
response.write("There's nothing wrong.")
end if
Dim objErr2
for each objErr2 in objConn.Errors
response.write("<p>")
response.write("Description: ")
response.write(objErr2.Description & "<br />")
response.write("Help context: ")
response.write(objErr2.HelpContext & "<br />")
response.write("Help file: ")
response.write(objErr2.HelpFile & "<br />")
response.write("Native error: ")
response.write(objErr2.NativeError & "<br />")
response.write("Error number: ")
response.write(objErr2.Number & "<br />")
response.write("Error source: ")
response.write(objErr2.Source & "<br />")
response.write("SQL state: ")
response.write(objErr2.SQLState & "<br />")
response.write("</p>")
next
Free(cmd)
Free(con)
In the stored procedure I simply RAISERROR( N'Lets throw an error because I want to!', 17, 0 );
The output I get every time is as follows ...
ASPCode=ASPDescription=Category=Column=-1Description=File=Line=0Number=0Source=
Description: Help context: Help file: Native error: Error number: Error source: SQL state:
Why am I not getting any error information on the conn.Errors loop?
Resolved.
I was using a different connection object for the loop that loops through the connection.Errors ... copy paste error.
However on a side note ... I found it extremely difficult to find information on how to even do what I've so far.
here's some additional resources:
some general topics:
http://social.msdn.microsoft.com/search/en-US?query=Server.GetLastError%28%29&refinement=89
a specific example:
http://support.microsoft.com/kb/224070

Resources