Link to home
Start Free TrialLog in
Avatar of Rob Bristow
Rob BristowFlag for United States of America

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:

  • 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\"}}"

    Open in new window

I did a fair amount of research, and came up with passing information through either WinHTTP or MSXML2 server object. The GET works like a charm to return XML, but can't seem to pass information through the post. Here's what I've done so far:

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

Avatar of HainKurt
HainKurt
Flag of Canada image

whats happening if you do

Call .Send(szData) 

and/or

use ' in your data instead of \"
can you test here

https://reqbin.com/

User generated image
Avatar of Rob Bristow

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
ASKER CERTIFIED SOLUTION
Avatar of Rob Bristow
Rob Bristow
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial