http://www.yiiframew...on/ehttpclient/
Bug Reports, Feedback highly appreciated.
Best!
Posted 27 December 2010 - 10:48 AM
Posted 04 January 2011 - 01:54 PM
Posted 04 January 2011 - 02:52 PM
David Dreggors, on 04 January 2011 - 01:54 PM, said:
Posted 04 January 2011 - 03:11 PM
Posted 04 January 2011 - 04:08 PM
Posted 04 January 2011 - 04:45 PM
Posted 04 January 2011 - 05:01 PM
Posted 18 October 2011 - 10:37 AM
Antonio Ramirez, on 27 December 2010 - 10:48 AM, said:
// protected/tests/functional/PagesControllerTest.php
<?php
Yii::import('ext.httpclient.*');
Yii::import('ext.httpclient.adapter.*');
class PagesControllerTest extends PHPUnit_Framework_TestCase {
public function testHome() {
$client = new EHttpClient(TEST_BASE_URL.'/pages/home');
$this->assertTrue($client->request()->isSuccessful());
}
public function testContact() {
$client = new EHttpClient(TEST_BASE_URL.'/pages/contact');
$this->assertTrue($client->request()->isSuccessful());
}
public function testError() {
$client = new EHttpClient(TEST_BASE_URL.'/pages/error-not-found');
$this->assertTrue($client->request()->isError());
}
public function testLoginLogout() {
$client = new EHttpClient(TEST_BASE_URL.'/site/login');
$client->setCookieJar();
$this->assertTrue($client->request()->isSuccessful());
$this->assertRegExp('/Login/', $client->request('POST')->getBody());
$client->resetParameters();
$client->setParameterPost(array(
'LoginForm[username]' => '',
'LoginForm[password]' => ''
));
$this->assertRegExp('/Username cannot be blank./', $client->request('POST')->getBody());
$this->assertRegExp('/Password cannot be blank./', $client->request('POST')->getBody());
$client->resetParameters();
$client->setParameterPost(array(
'LoginForm[username]' => 'wronguser',
'LoginForm[password]' => 'wrongpass'
));
$this->assertRegExp('/Incorrect username or password./', $client->request('POST')->getBody());
$client->resetParameters();
$client->setParameterPost(array(
'LoginForm[username]' => 'demo',
'LoginForm[password]' => 'demo'
));
$this->assertNotRegExp('/Username cannot be blank./', $client->request('POST')->getBody());
$this->assertNotRegExp('/Password cannot be blank./', $client->request('POST')->getBody());
$client->setUri(TEST_BASE_URL);
$this->assertTrue($client->request()->isSuccessful());
$this->assertRegExp('/Logout \(demo\)/', $client->request('POST')->getBody());
$client->setUri(TEST_BASE_URL.'/site/logout');
$this->assertTrue($client->request()->isSuccessful());
$client->setUri(TEST_BASE_URL);
$this->assertNotRegExp('/Logout \(demo\)/', $client->request('POST')->getBody());
}
}
Posted 18 October 2011 - 11:57 AM
Posted 06 January 2013 - 01:17 PM
I have a file named "auth" in a working directory
$ cat auth
{
"auth": {
"username": "myusername",
"password": "mypassword"
}
}
I issue the curl command as follows:
$ curl -b cookies -c cookies -X POST --data-binary @auth 'http://sand.api.appnexus.com/auth'
{
"response": {
"status": "OK",
"token": "7nod933p0o9pv6o2mg10i5g5u0"
}
}
After that my cookie holds the token so I can continue to issue commands to the server and return JSON data.
// Auth
$client = new EHttpClient('http://api.appnexus.com/auth', array(
'maxredirects' => 0,
'timeout' => 30));
// $auth = $client->setAuth('username', 'password', EHttpClient::AUTH_BASIC);
// $client->setParameterPost(array('auth'=>$auth));
$response = $client->request('POST');
if($response->isSuccessful())
echo '<pre>' . htmlentities($response->getBody()) .'</pre>';
else
echo $response->getRawBody();
$client = new EHttpClient('http://api.appnexus.com/category', array(
'maxredirects' => 0,
'timeout' => 30));