本文整理汇总了PHP中HTTP_Request2::getUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTP_Request2::getUrl方法的具体用法?PHP HTTP_Request2::getUrl怎么用?PHP HTTP_Request2::getUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTP_Request2
的用法示例。
在下文中一共展示了HTTP_Request2::getUrl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildEnvironment
/**
* Builds an array of post, get and server settings.
*
* @return array
*/
public function buildEnvironment(HTTP_Request2 $request)
{
$environment = array('_POST' => array(), '_GET' => array(), '_SERVER' => array());
if ($request->getPostParams()) {
$environment['_POST'] = $request->getPostParams();
}
$query = $request->getUrl()->getQuery();
if (!empty($query)) {
parse_str($query, $environment['_GET']);
}
$environment['_SERVER'] = $this->getServerGlobal($request->getConfig('host'), dirname($request->getConfig('index_file')), $request->getUrl(), $request->getMethod());
return $environment;
}
示例2: erzData
public function erzData($zip = null, $type = null, $page = 1)
{
if ($type) {
$url = 'http://openerz.herokuapp.com:80/api/calendar/' . $type . '.json';
} else {
$url = 'http://openerz.herokuapp.com:80/api/calendar.json';
}
//Http-request
$request = new HTTP_Request2($url, HTTP_Request2::METHOD_GET);
$reqUrl = $request->getUrl();
$pageSize = 10;
$reqUrl->setQueryVariable('limit', $pageSize);
$offset = ($page - 1) * $pageSize;
$reqUrl->setQueryVariable('offset', $offset);
if ($zip) {
$reqUrl->setQueryVariable('zip', $zip);
}
try {
$response = $request->send();
// 200 ist für den Status ob ok ist 404 wäre zum Beispiel ein Fehler
if ($response->getStatus() == 200) {
return json_decode($response->getBody());
}
} catch (HTTP_Request2_Exception $ex) {
echo $ex;
}
return null;
}
示例3: request
private function request($method, $path, $params = array())
{
$url = $this->api . rtrim($path, '/') . '/';
if (!strcmp($method, "POST")) {
$req = new HTTP_Request2($url, HTTP_Request2::METHOD_POST);
$req->setHeader('Content-type: application/json');
if ($params) {
$req->setBody(json_encode($params));
}
} else {
if (!strcmp($method, "GET")) {
$req = new HTTP_Request2($url, HTTP_Request2::METHOD_GET);
$url = $req->getUrl();
$url->setQueryVariables($params);
} else {
if (!strcmp($method, "DELETE")) {
$req = new HTTP_Request2($url, HTTP_Request2::METHOD_DELETE);
$url = $req->getUrl();
$url->setQueryVariables($params);
}
}
}
$req->setAdapter('curl');
$req->setConfig(array('timeout' => 30));
$req->setAuth($this->auth_id, $this->auth_token, HTTP_Request2::AUTH_BASIC);
$req->setHeader(array('Connection' => 'close', 'User-Agent' => 'PHPPlivo'));
$r = $req->send();
$status = $r->getStatus();
$body = $r->getbody();
$response = json_decode($body, true);
return array("status" => $status, "response" => $response);
}
示例4: 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;
}
示例5: testCookieJar
public function testCookieJar()
{
$this->request->setUrl($this->baseUrl . 'setcookie.php?name=cookie_name&value=cookie_value');
$req2 = clone $this->request;
$this->request->setCookieJar()->send();
$jar = $this->request->getCookieJar();
$jar->store(array('name' => 'foo', 'value' => 'bar'), $this->request->getUrl());
$response = $req2->setUrl($this->baseUrl . 'cookies.php')->setCookieJar($jar)->send();
$this->assertEquals(serialize(array('cookie_name' => 'cookie_value', 'foo' => 'bar')), $response->getBody());
}
示例6: testDigestAuth
public function testDigestAuth()
{
$this->request->getUrl()->setQueryVariables(array('user' => 'luser', 'pass' => 'qwerty'));
$wrong = clone $this->request;
$this->request->setAuth('luser', 'qwerty', HTTP_Request2::AUTH_DIGEST);
$response = $this->request->send();
$this->assertEquals(200, $response->getStatus());
$wrong->setAuth('luser', 'password', HTTP_Request2::AUTH_DIGEST);
$response = $wrong->send();
$this->assertEquals(401, $response->getStatus());
}
示例7: OXreqPUTforSendMail
public function OXreqPUTforSendMail($url, $QueryVariables, $PutData, $returnResponseObject = false)
{
$QueryVariables['timezone'] = 'UTC';
# all times are UTC,
$request = new HTTP_Request2(OX_SERVER . $url, HTTP_Request2::METHOD_PUT);
$request->setHeader('Content-type: text/javascript; charset=utf-8');
$url = $request->getUrl();
$url->setQueryVariables($QueryVariables);
$request->setBody(utf8_encode($PutData));
return $this->OXreq($request, $returnResponseObject);
}
示例8: delete
function delete($acct, Link $link)
{
$request = new HTTP_Request2($this->url, HTTP_Request2::METHOD_DELETE);
$query = $link->toArray();
$query['acct'] = $acct;
$request->getUrl()->setQueryVariables($query);
try {
$response = $request->send();
if (200 == $response->getStatus()) {
return $response->getBody();
} else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' . $response->getReasonPhrase();
return null;
}
} catch (HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
}
示例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: sendRequest
/**
* Returns the next response from the queue built by addResponse()
*
* Only responses without explicit URLs or with URLs equal to request URL
* will be considered. If matching response is not found or the queue is
* empty then default empty response with status 400 will be returned,
* if an Exception object was added to the queue it will be thrown.
*
* @param HTTP_Request2 $request HTTP request message
*
* @return HTTP_Request2_Response
* @throws Exception
*/
public function sendRequest(HTTP_Request2 $request)
{
$requestUrl = (string) $request->getUrl();
$response = null;
foreach ($this->responses as $k => $v) {
if (!$v[1] || $requestUrl == $v[1]) {
$response = $v[0];
array_splice($this->responses, $k, 1);
break;
}
}
if (!$response) {
return self::createResponseFromString("HTTP/1.1 400 Bad Request\r\n\r\n");
} elseif ($response instanceof HTTP_Request2_Response) {
return $response;
} else {
// rethrow the exception
$class = get_class($response);
$message = $response->getMessage();
$code = $response->getCode();
throw new $class($message, $code);
}
}
示例11: CheckForSpam
/**
* Check for spam links
*
* @param string $post post to check for spam
* @return boolean true = spam found, false = no spam
*
* Note: Also returns 'false' in case of problems communicating with SFS.
* Error messages are logged in glFusion's error.log
*
*/
function CheckForSpam($post)
{
global $_SPX_CONF, $REMOTE_ADDR;
require_once 'HTTP/Request2.php';
$retval = false;
$ip = $REMOTE_ADDR;
if (empty($post) || $ip == '') {
return $retval;
}
$request = new HTTP_Request2('http://www.stopforumspam.com/api', HTTP_Request2::METHOD_GET, array('use_brackets' => true));
$url = $request->getUrl();
$checkData['f'] = 'serial';
if ($ip != '') {
$checkData['ip'] = $ip;
}
$url->setQueryVariables($checkData);
$url->setQueryVariable('cmd', 'display');
try {
$response = $request->send();
} catch (Exception $e) {
return 0;
}
$result = @unserialize($response->getBody());
if (!$result) {
return false;
}
// invalid data, assume ok
if ($result['ip']['appears'] == 1 && $result['ip']['confidence'] > (double) 25) {
$retval = true;
SPAMX_log("SFS: spam detected");
} else {
if ($this->_verbose) {
SPAMX_log("SFS: no spam detected");
}
}
return $retval;
}
示例12: testPropagateUseBracketsToNetURL2
public function testPropagateUseBracketsToNetURL2()
{
$req = new HTTP_Request2('http://www.example.com/', HTTP_Request2::METHOD_GET, array('use_brackets' => false));
$req->getUrl()->setQueryVariable('foo', array('bar', 'baz'));
$this->assertEquals('http://www.example.com/?foo=bar&foo=baz', $req->getUrl()->__toString());
$req->setConfig('use_brackets', true)->setUrl('http://php.example.com/');
$req->getUrl()->setQueryVariable('foo', array('bar', 'baz'));
$this->assertEquals('http://php.example.com/?foo[0]=bar&foo[1]=baz', $req->getUrl()->__toString());
}
示例13: delete_mailinglist
public function delete_mailinglist($list)
{
$req = new HTTP_Request2($this->url . "/com/delmailinglistnow");
$req->setMethod(HTTP_Request2::METHOD_POST);
$req->getUrl()->setQueryVariables($this->auth);
$req->addPostParameter(array('modu' => $list));
$resp = $req->send();
// refresh lists in class
$this->get_mailinglists();
}
示例14: _fetch_by_options
public function _fetch_by_options()
{
// Set up our HTTP request
$options_array = array();
$options_array = array(Net_Url2::OPTION_USE_BRACKETS => false);
$net_url2 = new Net_Url2($this->url, $options_array);
$request = new HTTP_Request2($net_url2, HTTP_Request2::METHOD_GET, array('follow_redirects' => true, 'ssl_verify_peer' => false));
// The REST API requires these
$request->setHeader('Accept', 'application/json');
$request->setHeader('Content-Type', 'application/json');
// Save the real options
$saved_options = $this->options;
if (!isset($this->options['include_fields'])) {
$this->options['include_fields'] = array();
}
if (!is_array($this->options['include_fields'])) {
(array) $this->options['include_fields'];
}
// Add any synthetic fields to the options
if (!empty($this->synthetic_fields)) {
$this->options['include_fields'] = @array_merge((array) $this->options['include_fields'], $this->synthetic_fields);
}
if (!empty($this->options['include_fields'])) {
$this->options['include_fields'] = implode(",", $this->options['include_fields']);
}
// Add the requested query options to the request
$url = $request->getUrl();
$url->setQueryVariables($this->options);
// Retore the real options, removing anything we synthesized
$this->options = $saved_options;
// This is basically straight from the HTTP/Request2 docs
try {
$response = $request->send();
if (200 == $response->getStatus()) {
$this->data = json_decode($response->getBody(), TRUE);
} else {
$this->error = 'Server returned unexpected HTTP status: ' . $response->getStatus() . ' ' . $response->getReasonPhrase();
return;
}
} catch (HTTP_Request2_Exception $e) {
$this->error = $e->getMessage();
return;
}
// Check for REST API errors
if (isset($this->data['error']) && !empty($this->data['error'])) {
$this->error = "Bugzilla API returned an error: " . $this->data['message'];
}
}
示例15: _request
/**
* we use the Pear::\HTTP_Request2 for all the heavy HTTP protocol lifting.
*
* @param string $resource api-resource
* @param string $method request method [default:"GET"]
* @param array $data request data as associative array [default:array()]
* @param array $headers optional request header [default:array()]
*
* @throws ConnectionException
* @throws BadRequestError
* @throws UnauthorizedError
* @throws ForbiddenError
* @throws ConflictDuplicateError
* @throws GoneError
* @throws InternalServerError
* @throws NotImplementedError
* @throws ThrottledError
* @throws CCException
*
* @return string json encoded servers response
*/
private function _request($resource, $method = \HTTP_Request2::METHOD_GET, $data = array(), $headers = array())
{
$url = $this->_url . $resource;
$request = new \HTTP_Request2($url);
$request->setConfig(array('ssl_verify_peer' => API::SSL_VERIFY_PEER, 'ssl_cafile' => realpath(dirname(__FILE__)) . '/cacert.pem'));
$methods = array('options' => \HTTP_Request2::METHOD_OPTIONS, 'get' => \HTTP_Request2::METHOD_GET, 'head' => \HTTP_Request2::METHOD_HEAD, 'post' => \HTTP_Request2::METHOD_POST, 'put' => \HTTP_Request2::METHOD_PUT, 'delete' => \HTTP_Request2::METHOD_DELETE, 'trace' => \HTTP_Request2::METHOD_TRACE, 'connect' => \HTTP_Request2::METHOD_CONNECT);
$request->setMethod($methods[strtolower($method)]);
#
# If the current API instance has a valid token we add the Authorization
# header with the correct token.
#
# In case we do not have a valid token but email and password are
# provided we automatically use them to add a HTTP Basic Authenticaion
# header to the request to create a new token.
#
if ($this->_token) {
$headers['Authorization'] = sprintf('cc_auth_token="%s"', $this->_token);
} else {
if ($this->_email && $this->_password) {
$request->setAuth($this->_email, $this->_password, \HTTP_Request2::AUTH_BASIC);
}
}
#
# The API expects the body to be urlencoded. If data was passed to
# the request method we therefore use urlencode from urllib.
#
if (!empty($data)) {
if ($request->getMethod() == \HTTP_Request2::METHOD_GET) {
$url = $request->getUrl();
$url->setQueryVariables($data);
} else {
// works with post and put
$request->addPostParameter($data);
$request->setBody(http_build_query($data));
}
}
#
# We set the User-Agent Header to pycclib and the local version.
# This enables basic statistics about still used pycclib versions in
# the wild.
#
$headers['User-Agent'] = sprintf('phpcclib/%s', $this->_version);
#
# The API expects PUT or POST data to be x-www-form-urlencoded so we
# also set the correct Content-Type header.
#
if (strtoupper($method) == 'PUT' || strtoupper($method) == 'POST') {
$headers['Content-Type'] = 'application/x-www-form-urlencoded';
}
#
# We also set the Content-Length and Accept-Encoding headers.
#
//$headers['Content-Length'] = strlen($body);
$headers['Accept-Encoding'] = 'compress, gzip';
#
# Finally we fire the actual request.
#
foreach ($headers as $k => $v) {
$request->setHeader(sprintf('%s: %s', $k, $v));
}
for ($i = 1; $i < 6; $i++) {
try {
$response = $request->send();
return $this->_return($response);
} catch (\HTTP_Request2_Exception $e) {
# if we could not reach the API we wait 1s and try again
sleep(1);
# if we tried for the fifth time we give up - and cry a little
if ($i == 5) {
throw new ConnectionException('Could not connect to API...');
}
}
}
}