本文整理汇总了PHP中curl::getResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP curl::getResponse方法的具体用法?PHP curl::getResponse怎么用?PHP curl::getResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类curl
的用法示例。
在下文中一共展示了curl::getResponse方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_curl_useragent
/**
* Test curl agent settings.
*/
public function test_curl_useragent()
{
$curl = new testable_curl();
$options = $curl->get_options();
$this->assertNotEmpty($options);
$curl->call_apply_opt($options);
$this->assertTrue(in_array('User-Agent: MoodleBot/1.0', $curl->header));
$this->assertFalse(in_array('User-Agent: Test/1.0', $curl->header));
$options['CURLOPT_USERAGENT'] = 'Test/1.0';
$curl->call_apply_opt($options);
$this->assertTrue(in_array('User-Agent: Test/1.0', $curl->header));
$this->assertFalse(in_array('User-Agent: MoodleBot/1.0', $curl->header));
$curl->set_option('CURLOPT_USERAGENT', 'AnotherUserAgent/1.0');
$curl->call_apply_opt();
$this->assertTrue(in_array('User-Agent: AnotherUserAgent/1.0', $curl->header));
$this->assertFalse(in_array('User-Agent: Test/1.0', $curl->header));
$curl->set_option('CURLOPT_USERAGENT', 'AnotherUserAgent/1.1');
$options = $curl->get_options();
$curl->call_apply_opt($options);
$this->assertTrue(in_array('User-Agent: AnotherUserAgent/1.1', $curl->header));
$this->assertFalse(in_array('User-Agent: AnotherUserAgent/1.0', $curl->header));
$curl->unset_option('CURLOPT_USERAGENT');
$curl->call_apply_opt();
$this->assertTrue(in_array('User-Agent: MoodleBot/1.0', $curl->header));
// Finally, test it via exttests, to ensure the agent is sent properly.
// Matching.
$testurl = $this->getExternalTestFileUrl('/test_agent.php');
$extcurl = new curl();
$contents = $extcurl->get($testurl, array(), array('CURLOPT_USERAGENT' => 'AnotherUserAgent/1.2'));
$response = $extcurl->getResponse();
$this->assertSame('200 OK', reset($response));
$this->assertSame(0, $extcurl->get_errno());
$this->assertSame('OK', $contents);
// Not matching.
$contents = $extcurl->get($testurl, array(), array('CURLOPT_USERAGENT' => 'NonMatchingUserAgent/1.2'));
$response = $extcurl->getResponse();
$this->assertSame('200 OK', reset($response));
$this->assertSame(0, $extcurl->get_errno());
$this->assertSame('', $contents);
}
示例2: test_curl_post
public function test_curl_post()
{
$testurl = $this->getExternalTestFileUrl('/test_post.php');
// Test post request.
$curl = new curl();
$contents = $curl->post($testurl, 'data=moodletest');
$response = $curl->getResponse();
$this->assertSame('200 OK', reset($response));
$this->assertSame(0, $curl->get_errno());
$this->assertSame('OK', $contents);
// Test 100 requests.
$curl = new curl();
$curl->setHeader('Expect: 100-continue');
$contents = $curl->post($testurl, 'data=moodletest');
$response = $curl->getResponse();
$this->assertSame('200 OK', reset($response));
$this->assertSame(0, $curl->get_errno());
$this->assertSame('OK', $contents);
}
示例3: stdClass
} else {
$configfield = new stdClass();
$configfield->value = $value;
$configfield->plugin = 'plagiarism';
$configfield->name = $field;
if (!$DB->insert_record('config_plugins', $configfield)) {
error("errorinserting");
}
}
}
}
cache_helper::invalidate_by_definition('core', 'config', array(), 'plagiarism');
$c = new curl(array('proxy' => true));
$c->setopt(array('CURLOPT_HTTPAUTH' => CURLAUTH_BASIC, 'CURLOPT_USERPWD' => $data->urkund_username . ":" . $data->urkund_password));
$html = $c->post($data->urkund_api);
$response = $c->getResponse();
// Now check to see if username/password is correct. - this check could probably be improved further.
if ($c->info['http_code'] == '401') {
// Disable urkund as this config isn't correct.
$rec = $DB->get_record('config_plugins', array('name' => 'urkund_use', 'plugin' => 'plagiarism'));
$rec->value = 0;
$DB->update_record('config_plugins', $rec);
echo $OUTPUT->notification(get_string('savedconfigfailed', 'plagiarism_urkund'));
} else {
echo $OUTPUT->notification(get_string('savedconfigsuccess', 'plagiarism_urkund'), 'notifysuccess');
}
}
$invalidhandlers = urkund_check_event_handlers();
if (!empty($invalidhandlers)) {
echo $OUTPUT->notification("There are invalid event handlers - these MUST be fixed. Please use the correct procedure to uninstall any components listed in the table below.<br>\nThe existence of these events may cause this plugin to function incorrectly.");
$table = new html_table();
示例4: getAuthToken
/**
* $options['username'] and $options['password'] must be
* given, we will use them to obtain a valid auth_token
* To get a token, you should use following code:
*
* <code>
* $box = new boxclient('dmls97d8j3i9tn7av8y71m9eb55vrtj4');
* Get a ticket
* $t = $box->getTicket();
* $box->getAuthToken($t['ticket'], array(
* 'username'=>'dongsheng@moodle.com',
* 'password'=>'xxx'));
* </code>
*
* @param string $ticket
* @param string $username
* @param string $password
* @return mixed
*/
function getAuthToken($ticket, $username, $password)
{
$c = new curl(array('debug' => $this->debug));
$c->setopt(array('CURLOPT_FOLLOWLOCATION' => 0));
$param = array('login_form1' => '', 'login' => $username, 'password' => $password, 'dologin' => 1, '__login' => 1);
try {
$ret = $c->post('http://www.box.net/api/1.0/auth/' . $ticket, $param);
} catch (moodle_exception $e) {
$this->setError(0, 'connection time-out or invalid url');
return false;
}
$header = $c->getResponse();
if (empty($header['location'])) {
throw new repository_exception('invalidpassword', 'repository_boxnet');
}
$location = $header['location'];
preg_match('#auth_token=(.*)$#i', $location, $matches);
$auth_token = $matches[1];
if (!empty($auth_token)) {
$this->auth_token = $auth_token;
return $auth_token;
} else {
throw new repository_exception('invalidtoken', 'repository_boxnet');
}
}