Rob Bristow
asked on
Passing Curl data through ServerXMLHTTP in Classic ASP
One of my service providers changed their APIs and I need to generate a key rather than using username and password. They allow the output to be in XML, but are requiring the credentials to be passed in Curl. It's easy enough in their dev environment, and here is what they tell me I need as a command:
szData="{\" & Chr(34) & "user\" & Chr(34) & ":{\" & Chr(34) & "email\" & Chr(34) & ":\" & Chr(34) & "XXXXXX\" & Chr(34) & ",\" & Chr(34) & "password\" & Chr(34) & ":\" & Chr(34) & "XXXXXX\" & Chr(34) & ",\" & Chr(34) & "remember_me\" & Chr(34) & ":\" & Chr(34) & "true\" & Chr(34) & "}}"
if bTest then fpTest.WriteLine(szData)
Set objToken = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
With objToken
Call .Open("POST", "https://api.XXXXXX.com/api/v1/users/login.xml", False)
Call .SetRequestHeader("accept", "application/json")
Call .SetRequestHeader("Content-Type", "application/json")
Call .Send(Chr(34) & szData & Chr(34))
End With
if bTest then fpTest.Write(objToken.responseText)
Here's what was written to the output file:
{\"user\":{\"email\":\"XXXXXX\",\"password\":\"XXXXXX\",\"remember_me\":\"true\"}}
<?xml version="1.0" encoding="UTF-8"?>
<Errors>
<user type="array">
<user>can't be blank</user>
</user>
</Errors>
Using the syntax using the Chr(34) for the quote marks got me in the door, but not sure how to get any further.
I am open to any suggestions. This is part of a large legacy system (about 20 years old), so I can't rewrite in PHP or do anything drastic. The good news is I have access to the web server (Windows Server 2012 R2).
Hoping for responses other than "you're screwed".
Rob Bristow
Classic Club Solutions, LLC
curl -X POST "https://api.XXXXX.com/api/v1/users/login.xml" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"user\":{\"email\":\"XXXXX\",\"password\":\"XXXXX\",\"remember_me\":\"true\"}}"
szData="{\" & Chr(34) & "user\" & Chr(34) & ":{\" & Chr(34) & "email\" & Chr(34) & ":\" & Chr(34) & "XXXXXX\" & Chr(34) & ",\" & Chr(34) & "password\" & Chr(34) & ":\" & Chr(34) & "XXXXXX\" & Chr(34) & ",\" & Chr(34) & "remember_me\" & Chr(34) & ":\" & Chr(34) & "true\" & Chr(34) & "}}"
if bTest then fpTest.WriteLine(szData)
Set objToken = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
With objToken
Call .Open("POST", "https://api.XXXXXX.com/api/v1/users/login.xml", False)
Call .SetRequestHeader("accept", "application/json")
Call .SetRequestHeader("Content-Type", "application/json")
Call .Send(Chr(34) & szData & Chr(34))
End With
if bTest then fpTest.Write(objToken.responseText)
Here's what was written to the output file:
{\"user\":{\"email\":\"XXXXXX\",\"password\":\"XXXXXX\",\"remember_me\":\"true\"}}
<?xml version="1.0" encoding="UTF-8"?>
<Errors>
<user type="array">
<user>can't be blank</user>
</user>
</Errors>
Using the syntax using the Chr(34) for the quote marks got me in the door, but not sure how to get any further.
I am open to any suggestions. This is part of a large legacy system (about 20 years old), so I can't rewrite in PHP or do anything drastic. The good news is I have access to the web server (Windows Server 2012 R2).
Hoping for responses other than "you're screwed".
Rob Bristow
Classic Club Solutions, LLC
ASKER
Thanks for your replies. I did try just sending .Send(szData) as well as using single quote marks. Both returned Bad Request from API.
I'm not sure about the second request, but I'll see what I can learn from the instructions and let you know the results.
Rob
I'm not sure about the second request, but I'll see what I can learn from the instructions and let you know the results.
Rob
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Call .Send(szData)
and/or
use ' in your data instead of \"