Showing posts with label cURL. Show all posts
Showing posts with label cURL. Show all posts

Nov 25, 2013

CURL: Post request with payload/content body

Curl Command with a JSON Data
curl --header "Content-Type: application/json" -X POST -d '{"state": "----X----"}' http://localhost:8888/_ah/api/tictactoe/v1/board

Curl Command with POST Parameter
curl  -X POST -d 'key1=value1&key2=value2&' http://localhost:8888/_ah/api/tictactoe/v1/board







Curl Command with GET Parameter
curl  -X GET -d 'key1=value1&key2=value2&' http://localhost:8888/_ah/api/tictactoe/v1/board


This sample command get from tictactoe

Feb 14, 2013

Zend: Authenticating into server

Since, setAuth still not working. I rather manually set the parameter to the cURl.

$config = array(
    'maxredirects' => 3, // By defualt Zend_Http_Client use 5 max redirect
    'timeout'   => 500,
    //'adapter'   => 'Zend_Http_Client_Adapter_Curl',
);

$url = 'YOUR_URL_ADDRESS';

$client = new  Zend_Http_Client($url, $config);
$client->setAdapter('Zend_Http_Client_Adapter_Curl');
//$client->setAuth($this->_user, $this->_pass); // Since seems not working I use
$client->setParameterPost(array(
    'skuId' => $skuId,
    'username' => $this->_user,
    'password' => $this->_pass,
)); 

$client->getAdapter()
        ->setCurlOption(CURLOPT_USERPWD, $this->_user.':'.$this->_pass)
       ->setCurlOption(CURLOPT_HTTPAUTH, CURLAUTH_ANY)
       ->setCurlOption(CURLOPT_SSL_VERIFYPEER, false)
       ->setCurlOption(CURLOPT_RETURNTRANSFER, 1)
       ->setCurlOption(CURLOPT_POST, 1)
;
$this->_response = $client->request("POST");