本文整理汇总了PHP中HttpRequest::getResponseBody方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpRequest::getResponseBody方法的具体用法?PHP HttpRequest::getResponseBody怎么用?PHP HttpRequest::getResponseBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpRequest
的用法示例。
在下文中一共展示了HttpRequest::getResponseBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Performs the test.
*
* @return \Jyxo\Beholder\Result
*/
public function run()
{
// The http extension is required
if (!extension_loaded('http')) {
return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::NOT_APPLICABLE, 'Extension http missing');
}
$http = new \HttpRequest($this->url, \HttpRequest::METH_GET, array('connecttimeout' => 5, 'timeout' => 10, 'useragent' => 'JyxoBeholder'));
try {
$http->send();
if (200 !== $http->getResponseCode()) {
throw new \Exception(sprintf('Http error: %s', $http->getResponseCode()));
}
if (isset($this->tests['body'])) {
$body = $http->getResponseBody();
if (!preg_match($this->tests['body'], $body)) {
$body = trim(strip_tags($body));
throw new \Exception(sprintf('Invalid body: %s', \Jyxo\String::cut($body, 16)));
}
}
// OK
return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::SUCCESS);
} catch (\HttpException $e) {
$inner = $e;
while (null !== $inner->innerException) {
$inner = $inner->innerException;
}
return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, $inner->getMessage());
} catch (\Exception $e) {
return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, $e->getMessage());
}
}
示例2: doPost
protected function doPost($action, array $data)
{
$module = empty($action) ? substr($this->module, 0, -1) : $this->module;
if (strrpos($action, '.json') === false) {
$action .= '.json';
}
array_walk_recursive($data, 'Lupin_Model_API::encode');
$url = $this->hostname . $module . $action;
$request = new HttpRequest($url, HTTP_METH_POST);
$request->setPostFields($data);
try {
$request->send();
} catch (Exception $e) {
return false;
}
$this->responseCode = $request->getResponseCode();
if ($request->getResponseCode() !== 200) {
return false;
}
$json = json_decode($request->getResponseBody());
if (!is_object($json) && !is_array($json)) {
return false;
}
return $json;
}
示例3: execute
public static function execute($parameters)
{
$h = new \HttpRequest($parameters['server']['scheme'] . '://' . $parameters['server']['host'] . $parameters['server']['path'] . (isset($parameters['server']['query']) ? '?' . $parameters['server']['query'] : ''), static::$_methods[$parameters['method']], array('redirect' => 5));
if ($parameters['method'] == 'post') {
$h->setRawPostData($parameters['parameters']);
}
$h->send();
return $h->getResponseBody();
}
示例4: httpRequestSoapData
/**
* 2012年6月28日 携程 唐春龙 研发中心
* 通过httpRequest调用远程webservice服务(返回一个XML)
* @param $responseUrl 远程服务的地址
* @param $requestXML 远程服务的参数请求体XML
* @param 返回XML
*/
function httpRequestSoapData($responseUrl, $requestXML)
{
try {
$myhttp = new HttpRequest($responseUrl . "?WSDL", "POST");
//--相对于API2.0固定
$r_head = <<<BEGIN
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Request xmlns="http://ctrip.com/">
<requestXML>
BEGIN;
//--相对于API2.0固定
$r_end = <<<BEGIN
</requestXML>
</Request>
</soap:Body>
</soap:Envelope>
BEGIN;
//返回头--相对于API2.0固定
$responseHead = <<<begin
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><RequestResponse xmlns="http://ctrip.com/"><RequestResult>
begin;
//返回尾--相对于API2.0固定
$responseEnd = <<<begin
</RequestResult></RequestResponse></soap:Body></soap:Envelope>
begin;
$requestXML = str_replace("<", @"<", $requestXML);
$requestXML = str_replace(">", @">", $requestXML);
$requestXML = $r_head . $requestXML . $r_end;
//echo "<!--" . $requestXML ."-->";
$myhttp->open();
$myhttp->send($requestXML);
$responseBodys = $myhttp->getResponseBody();
//这里有可能有HEAD,要判断一下
if (strpos($responseBodys, "Content-Type: text/xml; charset=utf-8")) {
$coutw = $myhttp->responseBodyWithoutHeader;
} else {
$coutw = $responseBodys;
}
//$myhttp->responseBodyWithoutHeader;
//$coutw=$myhttp->responseBodyWithoutHeader;
$coutw = str_replace($responseHead, "", $coutw);
//替换返回头
$coutw = str_replace($responseEnd, "", $coutw);
//替换返回尾
$coutw = str_replace("<", "<", $coutw);
//将符号换回来
$coutw = str_replace(">", ">", $coutw);
//将符号换回来
// echo $coutw;
return $coutw;
} catch (SoapFault $fault) {
return $fault->faultcode;
}
}
示例5: returnWord
function returnWord()
{
$r = new HttpRequest('http://randomword.setgetgo.com/get.php?len=6', "GET");
$r->send();
if ($r->getStatus() == 200) {
return $_SESSION["word"] = $r->getResponseBody();
} else {
return "cannot generate music";
}
}
示例6: testGetAsset
public function testGetAsset()
{
$assetID = file_get_contents('test.assetid');
$sha = sha1(file_get_contents('eyewhite.tga'));
$r = new HttpRequest($this->server_url . $assetID, HttpRequest::METH_GET);
$r->send();
$this->assertEquals(200, $r->getResponseCode());
$assetData = $r->getResponseBody();
$this->assertEquals(sha1($assetData), $sha);
}
示例7: test
public function test()
{
$route = 'http://localhost/wordpress/augsburg/de/wp-json/extensions/v0/
modified_content/posts_and_pages';
$r = new HttpRequest($route, HttpRequest::METH_GET);
$r->addQueryData(array('since' => '2000-01-01T00:00:00Z'));
$r->send();
$this->assertEquals(200, $r->getResponseCode());
$body = $r->getResponseBody();
}
示例8: getCompetitionsPremierLeague
/**
* Permet d'avoir la liste de toutes les comp�titions.
* (Seul la Premier League est disponible avec un forfait gratuit)
* @return mixed
*/
public static function getCompetitionsPremierLeague()
{
$reqCometition = 'http://football-api.com/api/?Action=competitions&APIKey=' . self::API_KEY;
$reponse = new HttpRequest($reqCometition, HttpRequest::METH_GET);
try {
$reponse->send();
if ($reponse->getResponseCode() == 200) {
return json_decode($reponse->getResponseBody());
}
} catch (HttpException $ex) {
echo $ex;
}
}
示例9: fetchData
private static function fetchData($station, $time, $lang, $timeSel)
{
//temporal public credentials for the NS API.
$url = "http://" . urlencode("pieter@appsforghent.be") . ":" . urlencode("fEoQropezniTJRw_5oKhGVlFwm_YWdOgozdMjSAVPLk3M3yZYKEa0A") . "@webservices.ns.nl/ns-api-avt?station=" . $station->name;
$r = new HttpRequest($url, HttpRequest::METH_GET);
try {
$r->send();
if ($r->getResponseCode() == 200) {
return new SimpleXMLElement($r->getResponseBody());
}
} catch (HttpException $ex) {
throw new Exception("Could not reach NS server", 500);
}
}
示例10: execute
public static function execute($parameters) {
$h = new \HttpRequest($parameters['server']['scheme'] . '://' . $parameters['server']['host'] . $parameters['server']['path'] . (isset($parameters['server']['query']) ? '?' . $parameters['server']['query'] : ''), static::$_methods[$parameters['method']], array('redirect' => 5));
if ( isset($parameters['header']) ) {
$headers = array();
foreach ( $parameters['header'] as $header ) {
list($key, $value) = explode(':', $header, 2);
$headers[$key] = trim($value);
}
$h->setHeaders($headers);
}
if ( $parameters['method'] == 'post' ) {
$h->setBody($parameters['parameters']);
}
if ( $parameters['server']['scheme'] === 'https' ) {
$h->addSslOptions(array('verifypeer' => true,
'verifyhost' => true));
if ( isset($parameters['cafile']) && file_exists($parameters['cafile']) ) {
$h->addSslOptions(array('cainfo' => $parameters['cafile']));
}
if ( isset($parameters['certificate']) ) {
$h->addSslOptions(array('cert' => $parameters['certificate']));
}
}
$result = '';
try {
$h->send();
$result = $h->getResponseBody();
} catch ( \Exception $e ) {
if ( isset($e->innerException) ) {
trigger_error($e->innerException->getMessage());
} else {
trigger_error($e->getMessage());
}
}
return $result;
}
示例11: query_draw_history
/**
* Query past cashpot draws by date.
* @param day a two digit representation of the day eg. 09
* @param month a three letter representation of the month eg. Jan
* @param year a two digit representation of the year eg. 99
* @return the raw html from the page returned by querying a past cashpot draw.
*/
function query_draw_history($day, $month, $year)
{
$url = "http://www.nlcb.co.tt/search/cpq/cashQuery.php";
$fields = array('day' => $day, 'month' => $month, 'year' => $year);
$request = new HttpRequest($url, HttpRequest::METH_POST);
$request->addPostFields($fields);
try {
$request->send();
if ($request->getResponseCode() == 200) {
$response = $request->getResponseBody();
} else {
throw new Exception("Request for {$url} was unsuccessful. A " . $request->getResponseCode() . " response code was returned.");
}
} catch (HttpException $e) {
echo $e->getMessage();
throw $e;
}
return $response;
}
示例12: Login
public function Login()
{
$signature = $this->SignMessage("frob", $this->Frob, "perms", "delete");
$query = "api_key={$this->ApiKey}&perms=delete&frob={$this->Frob}&api_sig={$signature}";
$request = new HttpRequest("http://flickr.com/services/auth/", HTTP_METH_GET);
$request->setQueryData($query);
$request->enableCookies();
$request->setOptions(array( "redirect" => 10,
"useragent" => "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"
)
);
$request->send();
var_dump($request->getResponseCode());
print_r($request->getResponseBody());
var_dump($request->getResponseStatus());
}
示例13: http_get_file
function http_get_file($url)
{
$r = new HttpRequest($url, HttpRequest::METH_GET);
$r->setOptions(array('redirect' => 5));
try {
$r->send();
if ($r->getResponseCode() == 200) {
$dir = $r->getResponseBody();
} else {
echo "Respose code " . $r->getResponseCode() . "({$url})\n";
echo $r->getResponseBody() . "({$url})\n";
return "-2";
}
} catch (HttpException $ex) {
echo $ex;
return "-3";
}
$dir = strip_tags($dir);
return explode("\n", $dir);
// An array of lines from the url
}
示例14: fetch
public function fetch($query)
{
$request = new HttpRequest($this->getUrl(), HttpRequest::METH_GET);
$request->addQueryData(array($this->getParamName() => $query));
if (sfConfig::get('sf_logging_enabled')) {
sfContext::getInstance()->getLogger()->info(sprintf('Requesting search results for \'%s\'', $query));
}
try {
$request->send();
} catch (HttpException $e) {
if (sfConfig::get('sf_logging_enabled')) {
sfContext::getInstance()->getLogger()->info(sprintf('There is an error with the http request: %s', $e->__toString()));
}
}
$html = $request->getResponseBody();
$hit = $this->extractHit($html);
if (sfConfig::get('sf_logging_enabled')) {
sfContext::getInstance()->getLogger()->info(sprintf('Found %s results for \'%s\'', $hit, $query));
}
return $hit;
}
示例15: CreateBucket
/**
* The CreateBucket operation creates a bucket. Not every string is an acceptable bucket name.
*
* @param string $bucket_name
* @return string
*/
public function CreateBucket($bucket_name, $region = 'us-east-1')
{
$HttpRequest = new HttpRequest();
$HttpRequest->setOptions(array("redirect" => 10, "useragent" => "LibWebta AWS Client (http://webta.net)"));
$timestamp = $this->GetTimestamp(true);
switch ($region) {
case "us-east-1":
$request = "";
break;
case "us-west-1":
$request = "<CreateBucketConfiguration><LocationConstraint>us-west-1</LocationConstraint></CreateBucketConfiguration>";
break;
case "eu-west-1":
$request = "<CreateBucketConfiguration><LocationConstraint>EU</LocationConstraint></CreateBucketConfiguration>";
break;
}
$data_to_sign = array("PUT", "", "", $timestamp, "/{$bucket_name}/");
$signature = $this->GetRESTSignature($data_to_sign);
$HttpRequest->setUrl("https://{$bucket_name}.s3.amazonaws.com/");
$HttpRequest->setMethod(constant("HTTP_METH_PUT"));
$headers = array("Content-length" => strlen($request), "Date" => $timestamp, "Authorization" => "AWS {$this->AWSAccessKeyId}:{$signature}");
$HttpRequest->addHeaders($headers);
if ($request != '') {
$HttpRequest->setPutData($request);
}
try {
$HttpRequest->send();
$info = $HttpRequest->getResponseInfo();
if ($info['response_code'] == 200) {
return true;
} else {
if ($HttpRequest->getResponseBody()) {
$xml = @simplexml_load_string($HttpRequest->getResponseBody());
throw new Exception((string) $xml->Message);
} else {
throw new Exception(_("Cannot create S3 bucket at this time. Please try again later."));
}
}
} catch (HttpException $e) {
throw new Exception($e->__toString());
}
}