Hi i have a function that was created in ASP classic and want to convert the function in ASP.NET Vb . Below is code that was using in Classic ASP
Function chargeIt(CARD_NUM, EX_MONTH, EX_YEAR, AMOUNT, COMMENT)
url = "https://secure.authorize.net/gateway/transact.dll"
set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "POST", url, false
xmlhttp.send "x_description=""Violation Payment For "&COMMENT&"""&x_Version=3.1&x_Delim_Data=True&x_Login=xnxx&x_Tran_Key= 9&x_Amount="&amount&"&x_Card_Num="&card_num&"&x_Exp_Date="&ex_month&ex_year&"&x_Type=AUTH_CAPTURE"
Dim arrContents(150,0)
contents=split(xmlhttp.responseText,",")
'response.write(xmlhttp.responseText)
i=0
for each value in contents
arrContents(i,0)=value
i=i+1
next
SELECT CASE arrContents(0,0)
CASE "1"
status="Approved"
END SELECT
chargeIt=status
end function
You may use the System.Net.WebRequest class instead. It is part of the .NET Framework.
For example:
Dim strURL
Dim objXML As WebRequest
Dim strResponse As WebResponse
objXML = WebRequest.Create(strURL)
strResponse = objXML.GetResponse()
objXML = Nothing
strResponse.Close()
Google on WebRequest VB.NET and you should be able to get going...
Related
I have to integrate the razor payment to the asp classic and for this i have write the code for that is
razamt=razamt*100
dim options
set options = server.createObject("Scripting.Dictionary")
options.add "amount", razamt
options.add "receipt", "order_rcptid_11"
options.add "currency", "INR"
options.add "payment_capture", "0"
**Order order = client.Order.Create(options)**
getting issue in star marked line client is not available and i have no idea how to solve this
Please help me to fix this issue.
You should be able to do it using MSXML.ServerXMLHTTP, example
DataToSend = "amount=1&receipt=order_rcptid_11¤cy=INR&payment_capture=0"
set xmlhttp = server.Createobject("MSXML6.ServerXMLHTTP")
xmlhttp.Open "POST","https://api.razorpay.com/v1/orders",false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send DataToSend
Response.ContentType = "text/xml"
Response.Write xmlhttp.responsexml.xml
Set xmlhttp = nothing
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
I have set up a web service with an .asmx file and its web methods are being called via Ajax (all using asp.net scriptmanager etc) on the clientside.
When I call the webservice and look at the value of the return value in the callback, it is never in the 'SOAP' format, ie in xml. instead the value is returned in its raw form.
So for instance if I return a string from the webservice, the result passed to my successful callback is the string, not encoded or surrounded by XML tags.
How can I change this so I can see it in the SOAP format?
Are you calling from jquery? possible return in Json format. My guess without seeing your code.
It sounds like you are being returned the result of the web service function and letting .NET handle all of the underlying SOAP details. What you need to do if you want to see the HTTP SOAP response in your code, is instead of referencing the Web Service and invoking the function, issue an HTTP SOAP request. In VB.NET:
Dim _soapRequest As String = "<?xml version=""1.0"" encoding=""utf-8""?>" & _
"<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" & _
"<soap:Body>" & _
"<CelsiusToFahrenheit xmlns=""http://tempuri.org/"">" & _
"<Celsius>" & 100 & "</Celsius>" & _
"</CelsiusToFahrenheit>" & _
"</soap:Body>" & _
"</soap:Envelope>"
Dim response As String = DoRequestResponse(_soapRequest, "http://localhost:88/Service1.asmx")
and the DoRequestResponse Function looks like this
Public Function DoRequestResponse(ByVal _p_RequestString As String, ByVal _p_RequestURL As String) As String
Dim _httpWebRequest As HttpWebRequest
Dim _httpWebResponse As HttpWebResponse
Dim _streamReq As Stream
Dim _streamResp As Stream
Dim _streamReader As StreamReader
Dim _responseString As String
Dim _bytesToWrite() As Byte
Try
_httpWebRequest = CType(WebRequest.Create(_p_RequestURL), HttpWebRequest)
_httpWebRequest.Method = "POST"
_httpWebRequest.ContentType = "text/xml"
_httpWebRequest.Timeout = 30000
Dim EncodingType As System.Text.Encoding = System.Text.Encoding.UTF8
_bytesToWrite = EncodingType.GetBytes(_p_RequestString)
_streamReq = _httpWebRequest.GetRequestStream()
_streamReq.Write(_bytesToWrite, 0, _bytesToWrite.Length)
_streamReq.Close()
_httpWebResponse = DirectCast(_httpWebRequest.GetResponse(), HttpWebResponse)
_streamResp = _httpWebResponse.GetResponseStream()
_streamReader = New StreamReader(_streamResp)
_responseString = _streamReader.ReadToEnd()
_streamReader.Close()
_httpWebResponse.Close()
Catch ex As Exception
Dim _ex As WebException = ex
Console.Write(_ex.Status)
Console.Write(DirectCast(_ex.Response, HttpWebResponse).StatusCode)
Throw New Exception("DoRequestResponse Error :" & vbCrLf & ex.Message)
End Try
Return _responseString
End Function
You can do something like this in your code-behind of the asp.net page, and call it from AJAX, via postback, etc., which will then post to your .asmx web service and return the SOAP response.
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.
The code below works. But if I comment out the line Dim objRequest As MSXML2.XMLHTTP and uncomment the line Dim objRequest As Object it fails with the error message :
The parameter is incorrect
Why, and what (if anything) can I do about it?
Public Function GetSessionId(strApiId, strUserName, strPassword) As String
Dim strPostData As String
Dim objRequest As MSXML2.XMLHTTP
'Dim objRequest As Object '
strPostData = "api_id=" & strApiId & "&user=" & strUserName & "&password=" & strPassword
Set objRequest = New MSXML2.XMLHTTP
With objRequest
.Open "POST", "https://api.clickatell.com/http/auth", False
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.send strPostData
GetSessionId = .responseText
End With
End Function
Corey, yes, I know I would have to do that in order for my code to work without a reference to the MSXML type library. That's not the issue here. The code fails when using Dim objRequest As Object regardless of whether I use
Set objRequest = NEW MSXML2.XMLHTTP with the reference, or
Set objRequest = CreateObject("MSXML2.XMLHTTP") without the reference.
For some reason, this works:
Dim strPostData As String
Dim objRequest As Object
strPostData = "api_id=" & strApiId & "&user=" & strUserName & "&password=" & strPassword
Set objRequest = New MSXML2.XMLHTTP
With objRequest
.Open "POST", "https://api.clickatell.com/http/auth", False
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.send (strPostData)
GetSessionId = .responseText
End With
Instead of building the URL-encoded strPostData via string concatenation, it's strongly advisable to use a URL encoding function:
strPostData = "api_id=" & URLEncode(strApiId) & _
"&user=" & URLEncode(strUserName) & _
"&password=" & URLEncode(strPassword)
A couple of choices for a URLEncode() function in VBA are in this thread: How can I URL encode a string in Excel VBA?
If you use the Dim objRequest As Object then you would need to code:
Set objRequest = CreateObject("MSXML2.XMLHTTP")
I realise this is nearly identical to the code from Tomalek above (all credit due to you!), but this question helped me towards a full solution to a problem I had (Excel submitting to PHP server, then dealing with response)...so in case this is of any help to anyone else:
Sub Button1_Click2()
Dim objXMLSendDoc As Object
Set objXMLSendDoc = New MSXML2.DOMDocument
objXMLSendDoc.async = False
Dim myxml As String
myxml = "<?xml version='1.0'?><Request>Do Something</Request>"
If Not objXMLSendDoc.LoadXML(myxml) Then
Err.Raise objXMLSendDoc.parseError.ErrorCode, , objXMLSendDoc.parseError.reason
End If
Dim objRequest As MSXML2.XMLHTTP
Set objRequest = New MSXML2.XMLHTTP
With objRequest
.Open "POST", "http://localhost/SISADraftCalcs/Test2.php", False
.setRequestHeader "Content-Type", "application/xml;charset=UTF-16"
.setRequestHeader "Cache-Control", "no-cache"
.send objXMLSendDoc
End With
Dim objXMLDoc As MSXML2.DOMDocument
Set objXMLDoc = objRequest.responseXML
If objXMLDoc.XML = "" Then
objXMLDoc.LoadXML objRequest.responseText
If objXMLDoc.parseError.ErrorCode <> 0 Then
MsgBox objXMLDoc.parseError.reason
End If
End If
Dim rootNode As IXMLDOMElement
Set rootNode = objXMLDoc.DocumentElement
MsgBox rootNode.SelectNodes("text").Item(0).text
End Sub