Home > Backend Development > PHP Tutorial > laravel5 http如何请求另外一个api server

laravel5 http如何请求另外一个api server

WBOY
Release: 2016-06-06 20:30:25
Original
1333 people have browsed it

laravel5后端有什么好的方式http请求另外一个http server获取response信息呢?

<code>$request = Request::create('http://xxx', 'GET');
</code>
Copy after login
Copy after login

这种内置的方法好像获取不到response信息。

回复内容:

laravel5后端有什么好的方式http请求另外一个http server获取response信息呢?

<code>$request = Request::create('http://xxx', 'GET');
</code>
Copy after login
Copy after login

这种内置的方法好像获取不到response信息。

我比较喜欢用php-curl-class这个包

<code>php</code><code>use \Curl\Curl;

$curl = new Curl();
$curl->get('http://www.example.com/');


$curl = new Curl();
$curl->setBasicAuthentication('username', 'password');
$curl->setUserAgent('');
$curl->setReferrer('');
$curl->setHeader('X-Requested-With', 'XMLHttpRequest');
$curl->setCookie('key', 'value');
$curl->get('http://www.example.com/');

if ($curl->error) {
    echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
}
else {
    echo $curl->response;
}

var_dump($curl->requestHeaders);
var_dump($curl->responseHeaders);
</code>
Copy after login

https://github.com/php-curl-class/php-curl-class

创建请求不代表发送请求,简单的办法是curl,已经足够强大。如果想用封装好的包,你可以看下guzzle/guzzle这个HTTP客户端,laravel中应该已经引入了。

我想顶1L的,可惜声望不够

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template