Skip to main content
Inspiring
May 28, 2013
Question

Sending a CURL command

  • May 28, 2013
  • 1 reply
  • 1039 views

I know this is a bit obscure but I thought it would be pretty straightforward. The curl command I need to execute is

[my_user_name]:[my_password] -H "API-TOKEN: [api_token]" -H "API-VERSION: 0.1" https://domainOfInterest.com/api"

Given my very little curl experience, I came up with something along the lines of:

private var loader : HTTPURLLoader;

                    private var END_POINT : String = "[myDomainOfInterest]";

                    private var user : String = "[userName]";

                    private var password : String = "[myPassword]";

                    private var token: String = "[myToken";

  private function loadURL() : void {

                              var request : URLRequest = new URLRequest();

                              request.url = END_POINT;

                              var variables:URLVariables = new URLVariables();

                              variables.user = userName;

                              variables.password = myPassword;

                              var myToken : URLRequestHeader = new URLRequestHeader( "API-TOKEN", token );

                              request.requestHeaders.push( myToken );

                              var APIVersion : URLRequestHeader = new URLRequestHeader( "API-VERSION", "0.1" );

                              request.requestHeaders.push( APIVersion );

                              request.data = variables;

                              try {

                                        loader.load( request );

                              } catch ( error : SecurityError ) {

                                        Logger.error( "A SecurityError has occurred." );

                              }

                    }

I am not receiving any bad info (like unauthorized, which I was for awhile) but the data coming back is empty. Is the general form of what I'm trying to do correct?

This topic has been closed for replies.

1 reply

John_HallAuthor
Inspiring
May 29, 2013

In case anyone runs into this, I was able to solve my problem by adding one more request header

var JSONHeader : URLRequestHeader = new URLRequestHeader( "Accept", "application/json" );

BTW, since ActionScript doesn't support custom request headers with GET, I used

https://code.google.com/p/as3httpclient/