本文整理汇总了PHP中HTTP_Request2::setMethod方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTP_Request2::setMethod方法的具体用法?PHP HTTP_Request2::setMethod怎么用?PHP HTTP_Request2::setMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTP_Request2
的用法示例。
在下文中一共展示了HTTP_Request2::setMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send_post_data
function send_post_data($url, $data)
{
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2($url);
$request->setMethod(HTTP_Request2::METHOD_POST)->addPostParameter($data);
return $request->send();
}
示例2: get_request
/**
* GET Request
*
* @param $url
* @param $datas
* @return string
*/
public function get_request($url, $datas = array())
{
$body = '';
try {
$url2 = new Net_URL2($url);
foreach ($datas as $key => $val) {
$url2->setQueryVariable($key, mb_convert_encoding($val, $this->response_encoding, 'UTF-8'), true);
}
$this->http->setURL($url2);
$this->http->setMethod(HTTP_Request2::METHOD_GET);
if (!empty($this->cookies)) {
foreach ($this->cookies as $cookie) {
$this->http->addCookie($cookie['name'], $cookie['value']);
}
}
$response = $this->http->send();
if (count($response->getCookies())) {
$this->cookies = $response->getCookies();
}
$body = mb_convert_encoding($response->getBody(), 'UTF-8', $this->response_encoding);
} catch (Exception $e) {
debug($e->getMessage());
}
return $body;
}
示例3: fetchLunchMenus
/**
* さくら水産のランチ情報を取得する
*
* @return array | false
*/
public function fetchLunchMenus()
{
$menus = array();
$today = new DateTime();
$request = new HTTP_Request2();
$request->setMethod(HTTP_Request2::METHOD_GET);
$request->setUrl(self::LUNCHMENU_URL);
try {
$response = $request->send();
if (200 == $response->getStatus()) {
$dom = new DOMDocument();
@$dom->loadHTML($response->getBody());
$xml = simplexml_import_dom($dom);
foreach ($xml->xpath('//table/tr') as $tr) {
if (preg_match('/(\\d+)月(\\d+)日/', $tr->td[0]->div, $matches)) {
$dateinfo = new DateTime(sprintf('%04d-%02d-%02d', $today->format('Y'), $matches[1], $matches[2]));
$_menus = array();
foreach ($tr->td[1]->div->strong as $strong) {
$_menus[] = (string) $strong;
}
$menus[$dateinfo->format('Y-m-d')] = $_menus;
}
}
}
} catch (HTTP_Request2_Exception $e) {
// HTTP Error
return false;
}
return $menus;
}
示例4: testRawPostData
public function testRawPostData()
{
$data = 'Nothing to see here, move along';
$this->request->setMethod(HTTP_Request2::METHOD_POST)->setBody($data);
$response = $this->request->send();
$this->assertEquals($response->getBody(), $data);
}
示例5: __construct
private function __construct()
{
// sanity check
$siteUrl = get_option('siteurl');
$layoutUrl = DAIQUIRI_URL . '/core/layout/';
if (strpos($layoutUrl, $siteUrl) !== false) {
echo '<h1>Error with theme</h1><p>Layout URL is below CMS URL.</p>';
die(0);
}
// construct request
require_once 'HTTP/Request2.php';
$req = new HTTP_Request2($layoutUrl);
$req->setConfig(array('ssl_verify_peer' => false, 'connect_timeout' => 2, 'timeout' => 3));
$req->setMethod('GET');
$req->addCookie("PHPSESSID", $_COOKIE["PHPSESSID"]);
try {
$response = $req->send();
if (200 != $response->getStatus()) {
echo '<h1>Error with theme</h1><p>HTTP request status != 200.</p>';
die(0);
}
} catch (HTTP_Request2_Exception $e) {
echo '<h1>Error with theme</h1><p>Error with HTTP request.</p>';
die(0);
}
$body = explode('<!-- content -->', $response->getBody());
if (count($body) == 2) {
$this->_header = $body[0];
$this->_footer = $body[1];
} else {
echo '<h1>Error with theme</h1><p>Malformatted layout.</p>';
die(0);
}
}
示例6: sendRequest
/**
* Sends a request and returns a response
*
* @param CartRecover_Request $request
* @return Cart_Recover_Response
*/
public function sendRequest(CartRecover_Request $request)
{
$this->client->setUrl($request->getUri());
$this->client->getUrl()->setQueryVariables($request->getParams());
$this->client->setMethod($request->getMethod());
$this->client->setHeader('Accept', 'application/json');
$this->response = $this->client->send();
if ($this->response->getHeader('Content-Type') != 'application/json') {
throw new CartRecover_Exception_UnexpectedValueException("Unknown response format.");
}
$body = json_decode($this->response->getBody(), true);
$response = new CartRecover_Response();
$response->setRawResponse($this->response->getBody());
$response->setBody($body);
$response->setHeaders($this->response->getHeader());
$response->setStatus($this->response->getReasonPhrase(), $this->response->getStatus());
return $response;
}
示例7: request
/**
* Http request
*
* @param string $method
* @param string $url
* @param array $submit
* @param string $formName
*
* @return HTTP_Request2_Response
*/
public function request($method, $url, array $submit = array(), $formName = 'form')
{
$this->request = new HTTP_Request2();
$url = new Net_URL2($url);
$this->request->setMethod($method);
if ($submit) {
$submit = array_merge(array('_token' => '0dc59902014b6', '_qf__' . $formName => ''), $submit);
}
if ($submit && $method === 'POST') {
$this->request->addPostParameter($submit);
}
if ($submit && $method === 'GET') {
$url->setQueryVariables($submit);
}
$this->request->setUrl($url);
$this->response = $this->request->send();
return $this;
}
示例8: testPreventExpectHeader
/**
* @link http://pear.php.net/bugs/bug.php?id=19233
* @link http://pear.php.net/bugs/bug.php?id=15937
*/
public function testPreventExpectHeader()
{
$fp = fopen(dirname(dirname(dirname(__FILE__))) . '/_files/bug_15305', 'rb');
$observer = new HeaderObserver();
$body = new HTTP_Request2_MultipartBody(array(), array('upload' => array('fp' => $fp, 'filename' => 'bug_15305', 'type' => 'application/octet-stream', 'size' => 16338)));
$this->request->setMethod(HTTP_Request2::METHOD_POST)->setUrl($this->baseUrl . 'uploads.php')->setHeader('Expect', '')->setBody($body)->attach($observer);
$response = $this->request->send();
$this->assertNotContains('Expect:', $observer->headers);
$this->assertContains('upload bug_15305 application/octet-stream 16338', $response->getBody());
}
示例9: makeRequest
/**
* Make a request to the web2project api
*
* @access protected
*
* @param string action to be called
* @param array of parameters to pass to service
* @param string http_method type. GET, POST, PUT, DELETE, HEAD
* @param string type of request to make. Valid values = json, xml, html, printr, php, cli
* @param array of post/put vars
* @param array of credentials. array('username' => 'username', 'password' => 'password');
* @param string the base url of the tests
*
* @return HTTP_Request2_Response the response
*/
protected function makeRequest($action, $parameters, $http_method = 'GET', $post_array = null, $credentials = null, $url = 'http://w2p.api.frapi/', $type = 'json')
{
$url .= $action . '/';
foreach ($parameters as $param_value) {
$url .= $param_value . '/';
}
// Remove excess /
$url = substr($url, 0, strlen($url) - 1);
// add our type
$url .= '.' . $type;
$http_request = new HTTP_Request2($url);
switch (strtoupper($http_method)) {
case 'PUT':
$http_request->setMethod(HTTP_Request2::METHOD_PUT);
break;
case 'POST':
$http_request->setMethod(HTTP_Request2::METHOD_POST);
break;
case 'DELETE':
$http_request->setMethod(HTTP_Request2::METHOD_DELETE);
break;
case 'HEAD':
$http_request->setMethod(HTTP_Request2::METHOD_HEAD);
break;
case 'GET':
default:
break;
}
$url = $http_request->getUrl();
if (is_null($credentials)) {
$url->setQueryVariables(array('username' => 'admin', 'password' => 'passwd'));
} else {
$url->setQueryVariables(array('username' => $credentials['username'], 'password' => $credentials['password']));
}
if (!is_null($post_array) && count($post_array)) {
foreach ($post_array as $key => $value) {
$url->setQueryVariable($key, $value);
}
}
return $http_request->send();
}
示例10: post
protected static function post($url, $content)
{
$request = new HTTP_Request2($url);
$request->setMethod(HTTP_Request2::METHOD_POST);
foreach ($content as $name => $val) {
$request->addPostParameter($name, $val);
}
$request->setConfig(array('ssl_verify_peer' => false));
try {
$response = $request->send();
$body = $response->getBody();
return $body;
} catch (HTTP_Request2_Exception $e) {
return false;
}
}
示例11: callback
public static function callback()
{
global $HTTP_CONFIG;
//exchange the code you get for a access_token
$code = $_GET['code'];
$request = new HTTP_Request2(self::ACCESS_TOKEN_URL);
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig($HTTP_CONFIG);
$request->addPostParameter(['client_id' => GITHUB_APP_ID, 'client_secret' => GITHUB_APP_SECRET, 'code' => $code]);
$request->setHeader('Accept', 'application/json');
$response = $request->send();
$response = json_decode($response->getBody());
$access_token = $response->access_token;
//Use this access token to get user details
$request = new HTTP_Request2(self::USER_URL . '?access_token=' . $access_token, HTTP_Request2::METHOD_GET, $HTTP_CONFIG);
$response = $request->send()->getBody();
$userid = json_decode($response)->login;
//get the userid
//If such a user already exists in the database
//Just log him in and don't touch the access_token
$already_present_token = Token::get('github', $userid);
if ($already_present_token) {
$_SESSION['userid'] = $userid;
redirect_to('/');
}
if (defined('GITHUB_ORGANIZATION')) {
// perform the organization check
$request = new HTTP_Request2(json_decode($response)->organizations_url . '?access_token=' . $access_token, HTTP_Request2::METHOD_GET, $HTTP_CONFIG);
$response = $request->send()->getBody();
//List of organizations
$organizations_list = array_map(function ($repo) {
return $repo->login;
}, json_decode($response));
if (in_array(GITHUB_ORGANIZATION, $organizations_list)) {
$_SESSION['userid'] = $userid;
Token::add('github', $userid, $access_token);
} else {
throw new Exception('You are not in the listed members.');
}
} else {
$_SESSION['userid'] = $userid;
Token::add('github', $userid, $access_token);
}
redirect_to('/');
}
示例12: fetch
/**
* Fetches the HTML to be parsed
*
* @param string $url A valid URL to fetch
*
* @return string Return contents from URL (usually HTML)
*
* @throws Services_Mailman_Exception
*/
protected function fetch($url)
{
$url = filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED);
if (!$url) {
throw new Services_Mailman_Exception('Invalid URL', Services_Mailman_Exception::INVALID_URL);
}
try {
$this->request->setUrl($url);
$this->request->setMethod('GET');
$html = $this->request->send()->getBody();
} catch (HTTP_Request2_Exception $e) {
throw new Services_Mailman_Exception($e, Services_Mailman_Exception::HTML_FETCH);
}
if (strlen($html) > 5) {
return $html;
}
throw new Services_Mailman_Exception('Could not fetch HTML', Services_Mailman_Exception::HTML_FETCH);
}
示例13: postArticle
/**
* 記事を投稿する.
*
* @param string $title 記事タイトル
* @param string $text 記事本文
* @param string $category 記事カテゴリ
* @return string $res 結果
*/
public function postArticle($title, $text, $category)
{
try {
$req = new HTTP_Request2();
$req->setUrl(self::ROOT_END_POINT . $this->liveDoorId . "/" . self::END_POINT_TYPE_ARTICLE);
$req->setConfig(array('ssl_verify_host' => false, 'ssl_verify_peer' => false));
$req->setMethod(HTTP_Request2::METHOD_POST);
$req->setAuth($this->liveDoorId, $this->atomPubPassword);
$req->setBody($this->createBody($title, $text, $category));
$req->setHeader('Expect', '');
$res = $req->send();
} catch (HTTP_Request2_Exception $e) {
die($e->getMessage());
} catch (Exception $e) {
die($e->getMessage());
}
return $res;
}
示例14: send
/**
* Call webhook URLs with our payload
*/
public function send($event, Repository $repo)
{
if (count($this->config) == 0) {
return;
}
/* slightly inspired by
https://help.github.com/articles/post-receive-hooks */
$payload = (object) array('event' => $event, 'author' => array('name' => $_SESSION['name'], 'email' => $_SESSION['email']), 'repository' => array('name' => $repo->getTitle(), 'url' => $repo->getLink('display', null, true), 'description' => $repo->getDescription(), 'owner' => $repo->getOwner()));
foreach ($this->config as $url) {
$req = new \HTTP_Request2($url);
$req->setMethod(\HTTP_Request2::METHOD_POST)->setHeader('Content-Type: application/vnd.phorkie.webhook+json')->setBody(json_encode($payload));
try {
$response = $req->send();
//FIXME log response codes != 200
} catch (HTTP_Request2_Exception $e) {
//FIXME log exceptions
}
}
}
示例15: sendPOST
/**
* Send a POST request to the specified URL with the specified payload.
* @param string $url
* @param string $data
* @return string Remote data
**/
public function sendPOST($url, $data = array())
{
$data['_fake_status'] = '200';
// Send the actual request.
$this->instance->setHeader('User-Agent', sprintf(Imgur::$user_agent, Imgur::$key));
$this->instance->setMethod('POST');
$this->instance->setUrl($url);
foreach ($data as $k => $v) {
$this->instance->addPostParameter($k, $v);
}
try {
/** @var HTTP_Request2_Response */
$response = $this->instance->send();
return $response->getBody();
} catch (HTTP_Request2_Exception $e) {
throw new Imgur_Exception("HTTP Request Failure", null, $e);
} catch (Exception $e) {
throw new Imgur_Exception("Unknown Failure during HTTP Request", null, $e);
}
}