0

I have an issue and I am in need of some help. I have PHP version 4.4.7 and I want to POST data in API which uses MVC pattern and json data. I tried with get_file_contents method but i get 405 Error.

I want to pass three variable in the link below

http:...../api/create_customer?x=test&y=test1&y=test3

create_customer is the method I have to call and pass attributes. What does this version of PHP supports in order to connect with the credentials and post the data to the API. The possibility of upgrading the version is impossible so I have to find a way to do it in the current version.

kenda
  • 488
  • 6
  • 16
jim
  • 33
  • 4

1 Answers1

0

You can use curl. Example given below:

$content = json_encode($content);

$credentials = $userName . ':' . $password;

    $options = array(
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_SSL_VERIFYHOST => 2,
        CURLOPT_SSL_VERIFYPEER => 0,
        CURLOPT_USERPWD => $credentials,
        CURLOPT_HTTPHEADER => array('Content-type: application/json') ,
        CURLOPT_POSTFIELDS => $content,
        //Debug
        //CURLOPT_VERBOSE => 1
    );

    $ch = curl_init($url);

    curl_setopt_array($ch, $options);

    $result = curl_exec($ch);
devdoubts
  • 51
  • 7
  • curl is not added in the library how i am going to use it, it say curl init is not recognized – jim Sep 12 '16 at 14:00
  • Enable CURL via the php.inI Locate your PHP.ini file. (normally located at in the bin folder of your apache install e.g. Open the PHP.ini in notepad. Search or find the following : ';extension=php_curl.dll' Uncomment this by removing the semi-colon ';' before it. Save and Close PHP.ini. Restart Apache. – devdoubts Sep 19 '16 at 11:06