I have written code using asp classic and vb-script in payment.asp. i am posting data to 3rd party using winhttprequest and its submitting successfully and it works fine but my issue is:
after posting data, on 3rd party page, there is creating a unique ID which i want to retrieve on same page payment.asp
how can i retrieve unique ID created by 3rd party.
My code is as below given:
<%
Dim http, url, data
Set http = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
url = "https://www.instamojo.com/api/1.1/payment-requests/"
data = "amount=" & amount & "&buyer_name=" & buyer_name & "&purpose=" & purpose & "&redirect_url=" & redirect_url & "&phone=" & phone & "&send_email=" & send_email & "&send_sms=" & send_sms & "&email=" & email & ""
With http
Call .Open("POST", url, False)
Call .SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
Call .SetRequestHeader("X-Api-Key", "[X-Api-Key]")
Call .SetRequestHeader("X-Auth-Token", "[X-Auth-Token]")
Call .Send(data)
End With
If http.Status = 201 Then
Call Response.Write("succeeded: " & http.Status & " " & http.StatusText)
Else
Call Response.Write("Server returned: " & http.Status & " " & http.StatusText)
End If
%>
please help me.
Apparently the API's results are formatted in JSON. So you'll need a JSON parser like ASPJSON.
Include the aspJSON1.17.asp in your payment.asp and
after getting the response with 201 status code, parse the ID like this:
Set oJSON = New aspJSON
oJSON.loadJSON http.ResponseText
Response.Write oJSON.data("payment_request")("id")
Related
I am trying to make a simple form post to a remote server using MSXML and although this should be so simple I can't figure out why it fails. Let me explain...
CLIENT SCRIPT...
response.Buffer = true
Set objHTTP = CreateObject("Msxml2.ServerXMLHTTP")
objHTTP.open "POST","https://myurl.com/test_post_server.asp", false
PostData = "field1=test1&field2=test2&field3=test3"
objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
objHTTP.setRequestHeader "Content-Length", Len(PostData)
objHTTP.send PostData
strReturn = objHTTP.responseText
response.write strReturn
set objHTTP = nothing
REMOTE SERVER SCRIPT...
xResponse="No Form Data"
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
xResponse="Data Received" & "<Br>"
CNT=0
For Each fldName in Request.Form
CNT=CNT+1
xResponse = xResponse & Trim(CNT) & ": " & fldName & ": " & Request.Form(fldName) &"<br>"
Next
end if
response.write xResponse
The remote server see the request as a POST because it response as follows...
Data Received
But it does not see the Form.Request object. It should respond as follows...
Data Received
1: field1: test1
2: field2: test2
3: field3: test3
What am I doing wrong. I use this code all the time to submit form data locally. Does remote form submission have other requirements?
Is there a way to perform an HTTP GET request within a Visual Basic script? I need to get the contents of the response from a particular URL for processing.
Dim o
Set o = CreateObject("MSXML2.XMLHTTP")
o.open "GET", "http://www.example.com", False
o.send
' o.responseText now holds the response as a string.
You haven't at time of writing described what you are going to do with the response or what its content type is. An answer already contains a very basic usage of MSXML2.XMLHTTP (I recommend the more explicit MSXML2.XMLHTTP.3.0 progID) however you may need to do different things with the response, it may not be text.
The XMLHTTP also has a responseBody property which is a byte array version of the reponse and there is a responseStream which is an IStream wrapper for the response.
Note that in a server-side requirement (e.g., VBScript hosted in ASP) you would use MSXML.ServerXMLHTTP.3.0 or WinHttp.WinHttpRequest.5.1 (which has a near identical interface).
Here is an example of using XmlHttp to fetch a PDF file and store it:-
Dim oXMLHTTP
Dim oStream
Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP.3.0")
oXMLHTTP.Open "GET", "http://someserver/folder/file.pdf", False
oXMLHTTP.Send
If oXMLHTTP.Status = 200 Then
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write oXMLHTTP.responseBody
oStream.SaveToFile "c:\somefolder\file.pdf"
oStream.Close
End If
If you are using the GET request to actually SEND data...
check:
http://techhelplist.com/index.php/tech-tutorials/37-windows-troubles/60-vbscript-sending-get-request
The problem with MSXML2.XMLHTTP is that there are several versions of it, with different names depending on the windows os version and patches.
this explains it:
http://support.microsoft.com/kb/269238
i have had more luck using vbscript to call
set ID = CreateObject("InternetExplorer.Application")
IE.visible = 0
IE.navigate "http://example.com/parser.php?key=" & value & "key2=" & value2
do while IE.Busy....
....and more stuff but just to let the request go thru.
strRequest = "<soap:Envelope xmlns:soap=""http://www.w3.org/2003/05/soap-envelope"" " &_
"xmlns:tem=""http://tempuri.org/"">" &_
"<soap:Header/>" &_
"<soap:Body>" &_
"<tem:Authorization>" &_
"<tem:strCC>"&1234123412341234&"</tem:strCC>" &_
"<tem:strEXPMNTH>"&11&"</tem:strEXPMNTH>" &_
"<tem:CVV2>"&123&"</tem:CVV2>" &_
"<tem:strYR>"&23&"</tem:strYR>" &_
"<tem:dblAmount>"&1235&"</tem:dblAmount>" &_
"</tem:Authorization>" &_
"</soap:Body>" &_
"</soap:Envelope>"
EndPointLink = "http://www.trainingrite.net/trainingrite_epaysystem" &_
"/trainingrite_epaysystem/tr_epaysys.asmx"
dim http
set http=createObject("Microsoft.XMLHTTP")
http.open "POST",EndPointLink,false
http.setRequestHeader "Content-Type","text/xml"
msgbox "REQUEST : " & strRequest
http.send strRequest
If http.Status = 200 Then
'msgbox "RESPONSE : " & http.responseXML.xml
msgbox "RESPONSE : " & http.responseText
responseText=http.responseText
else
msgbox "ERRCODE : " & http.status
End If
Call ParseTag(responseText,"AuthorizationResult")
Call CreateXMLEvidence(responseText,strRequest)
'Function to fetch the required message from a TAG
Function ParseTag(ResponseXML,SearchTag)
ResponseMessage=split(split(split(ResponseXML,SearchTag)(1),"</")(0),">")(1)
Msgbox ResponseMessage
End Function
'Function to create XML test evidence files
Function CreateXMLEvidence(ResponseXML,strRequest)
Set fso=createobject("Scripting.FileSystemObject")
Set qfile=fso.CreateTextFile("C:\Users\RajkumarJoshua\Desktop\DCIM\SampleResponse.xml",2)
Set qfile1=fso.CreateTextFile("C:\Users\RajkumarJoshua\Desktop\DCIM\SampleReuest.xml",2)
qfile.write ResponseXML
qfile.close
qfile1.write strRequest
qfile1.close
End Function
OK so I have a script that goes through my outlook inbox looking for a particular header string. This works great for emails directly in my inbox. Now I'm trying to expand this detection to emails that contain other emails as attachments. I've spent significant time researching this and I can't seem to find the proper way to access the email attachment directly. What I've ended up doing is saving the attachment to disc and then reading it back in using CreateItemFromTemplate. I find this to be a cludge solution and I'm hoping someone here can help me find a more elegant way to do this where I can bypass the saveas as CreateItemFromTemplate and directly create an item object from the attachment. Here is proof of concept script I've put together for this:
Const olFolderInbox = 6
Const olMail = 43
Const olEmbeddeditem = 5
Const PropName = "http://schemas.microsoft.com/mapi/proptag/0x007D001E"
Set app = CreateObject("Outlook.Application")
set objNamespace = app.GetNamespace("MAPI")
set objInboxItems = objNameSpace.GetDefaultFolder(olFolderInbox).items
wscript.echo "Have your inbox open checking for fish tests or emails as attachments"
for each objItem in objInboxItems
if objItem.Class = olMail then
with objItem
strHeader = .PropertyAccessor.GetProperty(PropName)
iLoc1 = instr(1,strHeader,"X-Testing",1)
if iLoc1 > 0 then
wscript.echo "mytest. From: " & .Sender & " at: " & .ReceivedTime & " subjet: " & .Subject
end if
iLoc1 = instr(1,strHeader,"X-PHISHTEST",1)
if iLoc1 > 0 then
wscript.echo "Go Fish. From: " & .Sender & " at: " & .ReceivedTime & " subjet: " & .Subject
end if
if .attachments.count > 0 then
set objAttachment = .attachments.item(1)
if objAttachment.type = olEmbeddeditem then
wscript.echo "Has Attachment. From: " & .Sender & " at: " & .ReceivedTime & " subjet: " & .Subject
wscript.echo " - Filename: " & objAttachment.Filename
objAttachment.SaveAsFile ("c:\temp\TempEmail.msg")
set objExtMsg = app.CreateItemFromTemplate("c:\temp\TempEmail.msg")
strExtHeader = objExtMsg.PropertyAccessor.GetProperty(PropName)
iLoc1 = instr(1,strExtHeader,"X-Testing",1)
if iLoc1 > 0 then wscript.echo " ++ This is a plain test message"
end if
end if
end with
end if
next
wscript.echo "That's all folks" `
That is the best you can do in OOM alone - save the attachment as an MSG file and then reopen it. OpenSharedItem is a better way to open an MSG file than CreateItemFromTemplate.
On the Extended MAPI level (C++ or Delphi), you can open the PR_ATTACH_DATA_OBJ property as IMessage using IAttach::OpenProperty. If Extended MAPI is not an option, you can use Redemption (I am its author - any language) - both Safe*Item and RDO families of objects expose EmbeddedMsg property on the attachment object that return the attachment message.
I have the following code, which used to work perfectly, But now for somes reason, doesn't.
The XML I am reading is located at: https://forex.boi.org.il/currency.xml
The following code should parse the XMl and then save the USD/ILS exchange rate. As I say, it doesnt anymore, and I cant figure out whats wrong.
forexURL = "https://forex.boi.org.il/currency.xml"
getUSDRate = 0
MyRate = 0
Set xmlObj = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
xmlObj.async = False
xmlObj.setProperty "ServerHTTPRequest", True
xmlObj.Load(forexURL)
Set xmlList = xmlObj.getElementsByTagName("CURRENCY")
Set xmlObj = Nothing
x = 1
For Each xmlItem In xmlList
response.write "<p>" & xmlItem.childNodes(0).text
response.write "<p>" & xmlItem.childNodes(1).text
response.write "<p>" & xmlItem.childNodes(2).text
response.write "<p>" & xmlItem.childNodes(3).text
response.write "<p>" & xmlItem.childNodes(4).text
response.write "<p>" & xmlItem.childNodes(5).text
response.write "<p>___________________<br />" & x & "</p>"
if xmlItem.childNodes(2).text = "USD" then
MyRate = xmlItem.childNodes(4).text
exit for
end if
x = x +1
Next
Set xmlList = Nothing
I suspect (wild guess ahead) changes to the way SSL is handled on the server side as the cause of your trouble. Maybe they disabled older, more insecure ciphers in response to recent SSL bugs.
Like #John notes - when you change from MSXML2.FreeThreadedDOMDocument (which loads version MSXML2 version 3) to explicitly load the more modern version 6 (MSXML2.FreeThreadedDOMDocument.6.0) then the download of the document succeeds.
That being said I've made a few changes to your code, mostly to be more readable and make it fail visibly when the document load fails for some reason.
Note
the use of XPath
a helper function GetText() in place of blindly indexing into child nodes
the parseError check to make LoadXmlDocument fail non-silently
.
Option Explicit
Dim usdRate, x, currencies, curr
Set currencies = LoadXmlDocument("https://forex.boi.org.il/currency.xml")
usdRate = GetText(currencies, "//CURRENCY[CURRENCYCODE = 'USD']/RATE")
x = 1
For Each curr In currencies.getElementsByTagName("CURRENCY")
Response.Write "<p>" & GetText(curr, "NAME") & "</p>"
Response.Write "<p>" & GetText(curr, "UNIT") & "</p>"
Response.Write "<p>" & GetText(curr, "CURRENCYCODE") & "</p>"
Response.Write "<p>" & GetText(curr, "COUNTRY") & "</p>"
Response.Write "<p>" & GetText(curr, "RATE") & "</p>"
Response.Write "<p>" & GetText(curr, "CHANGE") & "</p>"
Response.Write "<p>___________________<br />" & x & "</p>"
x = x + 1
Next
' ----------------------------------------------------------------------
' loads an XML document from a URL and returns it
Function LoadXmlDocument(url)
Set LoadXmlDocument = CreateObject("MSXML2.FreeThreadedDOMDocument.6.0")
LoadXmlDocument.async = False
LoadXmlDocument.setProperty "ServerHTTPRequest", True
LoadXmlDocument.setProperty "SelectionLanguage", "XPath"
LoadXmlDocument.Load url
If LoadXmlDocument.parseError <> 0 Then
Err.Raise vbObjectError + 1, _
"LoadXmlDocument", _
"Cannot load " & url & " (" & LoadXmlDocument.parseError.reason & ")"
End If
End Function
' finds the first node that matches the XPath and returns its text value
Function GetText(context, xpath)
Dim node
Set node = context.selectSingleNode(xpath)
If node Is Nothing Then
GetText = vbEmpty
Else
GetText = node.text
End If
End Function
I just tried this on my machine. Try replacing
Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
with
Server.CreateObject("Msxml2.DomDocument.6.0")
Edit
Server.CreateObject("MSXML2.FreeThreadedDOMDocument.6.0")
also seems to work
I am trying to send an email via Outlook from within a VB6 program. Everything is working fine so far, and my emails get sent successfully. I would like to send the recipient a link in the body of the email, however, that sends them to a network directory. I can't seem to get a hyperlink in the body of the email.
My code for sending the email thus far looks like this:
Dim outlookApp As Outlook.Application
Dim resultsEmail As Outlook.MailItem
Set outlookApp = CreateObject("Outlook.Application")
Set resultsEmail = Outlook.CreateItem(olMailItem)
With resultsEmail
.To = addressee
.Subject = emailSubject
.Body = "Results are available here: " & 'somehow put in a hyperlink
.Send
End With
addressee and emailSubject are just strings created earlier in the code.
I tried inserting an HTML link using VB6's horrific quote escapes, hoping Outlook would magically sort it out:
"<a href" & ch=" & chr(34) & "directoryLocation" & chr(34) & ">Link text</a>"
But it doesn't create the hyperlink, it just puts the resulting text in the body of the email:
Link text
How can I get a link in the generated email?
Looks like I found the answer and it was deceptively simple. Instead of using .body, I needed to insert the HTML link as I posted and use .HTMLBody instead:
With resultsEmail
.To = addressee
.Subject = emailSubject
.HTMLBody = "Results are available here: " & _
"<a href" & ch=" & chr(34) & "directoryLocation" & chr(34) & ">Link text</a>"
.Send
End With