cancel
Showing results for 
Search instead for 
Did you mean: 

Perl and AIM: Bad Request (Invalid Header Name)

Hello,

 

I have rewritten a working Wordpress website using perl, and the last thing to do is implement Authorize.Net integration before I can replace the original website. Since there doesn't seem to be perl support for DPM yet, I am using AIM. Unfortunately I can't get out of the starting gate. When I post a request, all I get back is: "<h1>Bad Request (Invalid Header Name)</h1>". My code is below (minus the login information). Any help would be GREATLY appreciated.

 

  my $PostURL = 'https://secure.authorize.net/gateway/transact.dll';
  my %PostVals = {
    "x_login"        => "XXXXXXX",
    "x_tran_key"    => "XXXXXXXXXXXXXX",
    "x_test_request"    => "TRUE",
    
    "x_version"        => "3.1",
    "x_delim_data"    => "TRUE",
    "x_delim_char"    => "|",
    "x_relay_response"    => "FALSE",
    
    "x_type"        => "AUTH_CAPTURE",
    "x_method"        => "CC",
    "x_card_num"    => "4222222222222",
    "x_exp_date"    => "0115",
    
    "x_amount"        => "1.00",
    "x_description"    => "Sample Transaction",
    
    "x_first_name"    => "John",
    "x_last_name"    => "Doe",
    "x_address"        => "1234 Street",
    "x_state"        => "WA",
    "x_zip"        => "98004"    
  };

  my $UA = LWP::UserAgent->new( protocols_allowed => ["https"] );
  my $Request = POST( $PostURL, $PostVals );
  my $Response = $UA->request( $Request );

  warn "HOWDY: " . $Response->content;

James

nontrivial
Member
1 ACCEPTED SOLUTION

Accepted Solutions

I believe the problem is that your post values are in a hash (%PostVals), but what you are posting is a scalar.  I think this code is incorrect:

my %PostVals = {
    "x_login"        => "XXXXXXX",
    ...
    "x_zip"        => "98004"    
  };

 It should be:

my $PostVals = {
    "x_login"        => "XXXXXXX",
    "...
    "x_zip"        => "98004"    
  };

 This will create a hash reference, which is what this code is expecting:

my $Request = POST( $PostURL, $PostVals );

 Regards,

John

View solution in original post

jgoebel
Contributor
5 REPLIES 5

OK, I dug around on the forums some more (I did before I posted, honest, I just tried harder after), and tried:

 

  my $Request = HTTP::Request->new(POST =>"$PostURL");
  $Request->content_type('application/x-www-form-urlencoded');
  $Request->content('match=www&errors=0');

 

Instead of the example code of:


  my $Request = POST( $PostURL, $PostVals );

And I got a response. It was an API error about an invlaid login, but hey, it's progress. :-) I REALLY suggest that the sample perl needs to be updated.

 

James

nontrivial
Member

I believe the problem is that your post values are in a hash (%PostVals), but what you are posting is a scalar.  I think this code is incorrect:

my %PostVals = {
    "x_login"        => "XXXXXXX",
    ...
    "x_zip"        => "98004"    
  };

 It should be:

my $PostVals = {
    "x_login"        => "XXXXXXX",
    "...
    "x_zip"        => "98004"    
  };

 This will create a hash reference, which is what this code is expecting:

my $Request = POST( $PostURL, $PostVals );

 Regards,

John

jgoebel
Contributor

John,

 

Thank you for the response. In my followup, I added some code and I started getting an API response. Unfortunately it is the dreaded error 13 error, no matter what combination of server and test/production credentials I use. I did try your suggested fix, and that unfortunately didn't seem to help.

 

James

Crap, I spoke too soon. I made that change AND reverted the code I change back to the sample code, and it worked! Thanks!

 

James

James,

Glad it works now.

On the subject of perl and DPM, DPM is just SIM with some additions. I had great difficulty with DPM because the documentation does not give a clear explanation of  exactly how the redirects work - or at least I failed to understand it. I was able to get DPM to work after reading this post  which does a much better job of explaining the fundamentals than the DPM documentation does.

Regards,

John