sendgrid in classic asp add email category - asp-classic

I'm sending mail using sendgrid web API successfully but unable add categories into x-smtpapi.
Here is my code :
function getHTML (strUrl,postData)
Set xmlHttp = Server.Createobject("MSXML2.ServerXMLHTTP")
xmlHttp.Open "POST", strUrl, False
xmlHttp.setRequestHeader "User-Agent", "asp httprequest"
xmlHttp.setRequestHeader "content-type", "application/x-www-form-urlencoded"
'xmlHttp.AddHeader "category", "web"
xmlHttp.Send postData
getHTML = xmlHttp.responseText
xmlHttp.abort()
set xmlHttp = Nothing
end function
Response.Write("test->" & getHTML("https://sendgrid.com/api/mail.send.json","api_user=myusername&api_key=mykey&to=soneone#somemail.com&subject=test-1 msg&html=this is test message&from=info#zyxxxz.com&category={testweb}"))
Response.End()
I've checked some doc here
But I could not find any way to add categories.
EDIT
Response.Write("test->" & getHTML("https://sendgrid.com/api/mail.send.json","api_user=user&api_key=key&to=somemail#somemail.com&subject=test-1 msg&html=this is test message&from=info#xyzzz.com&x-smtpapi={"category":"testCategory"}"))
I need to post it JSON. If I do not put double quote x-smtpapi={"category":"testCategory"}" JSON parser can't parse it!

A double double quote escapes in ASP:
Ex.
#Invalid
str = " She said "Hello World" to the whole group"
#valid
str = " She said ""Hello World"" to the whole group"
So this should work fine:
Response.Write("test->" & getHTML("https://sendgrid.com/api/mail.send.json","api_user=user&api_key=key&to=somemail#somemail.com&subject=test-1 msg&html=this is test message&from=info#xyzzz.com&x-smtpapi={""category"":""testCategory""}"))

Related

How to integrate razor payment to the asp classic?

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&currency=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

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

POST Parameters not passing to Web API using VBA

I have a bog standard WebAPI that accepts a POST and takes those parameters and processes certain things. I'm not certain if the problem is the VBA or the ASP.Net WebAPI so I am cross posting.
I've used Postman to test the API and it works fine when I post Key/Value params.
I've also tried the following method and relevant parameters and get the same result:
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
I'm having problems getting it to work with the VBA, when debugging in Visual Studio on the WebAPI I cannot see the values I am posting anywhere. It's like the request is coming in blank. My WebAPI is subsequently throwing an error because the parameters are missing and certain parameters are required.
I'm not sure if this is a problem on the VBA side or the ASP.NET WebAPI side so I am cross posting in a hope someone can highlight or spot what I am doing wrong.
Private Sub Command4_Click()
Dim argumentString1 As String
argumentString1 = "companyId=228&secondsToLog=15&subject=TestBackup123&description=TestDescription" & _
"&category=&tag=&ticketType=task&assignee=gavin&requesterEmail=bob#smith.com" & _
"&submitterName=gavin&status=open&priority=normal"
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
URL = "http://localhost:64874/api/zendeskhelper"
objHTTP.Open "POST", URL, False
objHTTP.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
objHTTP.send (argumentString1)
txtresult = objHTTP.responsetext & ": " & argumentString1
End Sub
The Web API structure looks like this:
public HttpResponseMessage Post([FromUri] TicketBody ticket)
{
// Nothing is bound to ticket like it is in Postman
}
Any help or pointers would be much appreciated!
The way you are sending your data, you need to remove [FromUri]. When using [FromUri], the ASP.NET engine will look for data in the Uri, not the body of the request.
public HttpResponseMessage Post(TicketBody ticket)
{
// 'ticket should not be null now
}
On the other hand, if you need to keep [FromUri] you could change your call to:
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
URL = "http://localhost:64874/api/zendeskhelper?" & argumentString1
objHTTP.Open "POST", URL, False
objHTTP.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
objHTTP.send ("")

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