API Rest returning 405 php

Asked

Viewed 65 times

0

I am running the following code:

<?php

  $data_string['MerchantOrderId']                             = "2014111703";
  $data_string['Customer']['Name']                            = "Comprador Teste";
  $data_string['Payment']['Type']                             = "CreditCard";           
  $data_string['Payment']['Amount']                           = '15700';
  $data_string['Payment']['Provider']                         = "Simulado";
  $data_string['Payment']['Installments']                     = '1';
  $data_string['Payment']['CreditCard']['CardNumber']         = "1234123412341231";
  $data_string['Payment']['CreditCard']['Holder']             = "Teste Holder";
  $data_string['Payment']['CreditCard']['ExpirationDate']     = "12/2021";
  $data_string['Payment']['CreditCard']['SecurityCode']       = "123";
  $data_string['Payment']['CreditCard']['Brand']              = "Visa";

  $data_string = json_encode($data_string);

  $data = json_encode($data_string);

$ch = curl_init('https://apihomolog.braspag.com.br/');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'MerchantId: 1688adsasdasdasdasdasda',
'MerchantKey: adasdasdasdsadasdaswoT')
);

$result = curl_exec($ch);

echo '<pre>';
print_r($result);

The API is returning: 405 - HTTP Verb used to access this page is not allowed.

How do I see the answer without the error ?

  • In a Rest API, the response code usually indicates the problem. "Verb used to access this page is not allowed." Apparently you cannot send a POST to this url.

  • To complement the previous comment, check the API documentation and see which verbs this URL is waiting for or accepting. Another thing, I believe you can delete one of the lines: $data_string = json_encode($data_string); $data = json_encode($data_string);

  • Had not noticed, you are sending a POST to the index. Normally, not even "amateur" sites (which by nature are poorly structured), usually have some functionality related to the POST at the root, imagine then a Rest API.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.