We help IT Professionals succeed at work.
Get Started

php curl help

ammadeyy2020
ammadeyy2020 asked
on
944 Views
Last Modified: 2012-08-23
<?php
/**
 *
 * A class made for utility methods around Vend's API
 *
 *
 */
class VendApiUtils {

    /**
     * A simple static method to call Vend API urls
     *
     * @param string $url
     * @param string $username
     * @param string $password
     * @param array  $params	<OPTIONAL>
     */
    public static function requestVendApiUrl($url, $username, $password, $params = array())
    {
        // is cURL installed?
        if (!function_exists('curl_init')) {
            throw new Exception('CURL is not installed!');
        }

        // Create a new cURL instance
        $ch = curl_init();
        
        $opts = array(
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_POST => 1,
        CURLOPT_POSTFIELDS => array('data' => json_encode($params)),
        CURLOPT_TIMEOUT => 120,
        CURLOPT_FAILONERROR => 1,
        CURLOPT_HTTPAUTH => CURLAUTH_ANY, 
        CURLOPT_USERPWD => "$username:$password"         
        );

        // Assign the cURL options
        curl_setopt_array($ch, $opts);
        
        // Get the response
        $response = curl_exec($ch);
        
        // Close cURL
        curl_close($ch);
        
        // Execute the request & get the response
        return $response;
    }
}

Open in new window


i have created test store in vendhq.com
store url is https://mystore.vendhq.com
username : test
password : test123

i changed line 29
CURLOPT_URL => $https://mystore.vendhq.com

error i am getting is
Parse error: syntax error, unexpected ':', expecting ')'

which line i should change to login to store name?
Comment
Watch Question
Most Valuable Expert 2011
Author of the Year 2014
Commented:
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE