$page1 = file_get_contents('http://www.google.com');
$page2 = file_get_contents('http://localhost:8000/prueba');
Run Code Online (Sandbox Code Playgroud)
当我回应结果时,谷歌它可以工作,但不适用于我的网站.当我把地址放在资源管理器上时.这发生在我在django制作的所有网站上.:(
警告:file_get_contents(http://localhost:8000/prueba)[function.file-get-contents]:无法打开流:连接尝试失败,因为连接方在一段时间后没有正确响应,或者由于连接主机无法响应而建立连接失败.在第138行的C:\ xampp\htdocs\squirrelmail\plugins\captcha\backends\b2evo\b2evo.php中
致命错误:第138行的C:\ xampp\htdocs\squirrelmail\plugins\captcha\backends\b2evo\b2evo.php超出最长执行时间60秒
目前使用 Laravel 5.5 和与 Laravel 安装程序一起提供的 Guzzle。
我正在尝试发出 GET 请求(其他 HTTP 请求也会发生错误),但似乎不起作用。
此代码不起作用:
public function callback(Request $request)
{
$code = $request->code;
$client = new Client(['exceptions' => false]);
try {
$response = $client->request('GET', 'http://localhost/api/tests');
// $response = $http->request('POST', Config::get('app.url') . '/oauth/token', [
// 'form_params' => [
// 'grant_type' => 'authorization_code',
// 'client_id' => Config::get('oauth_client.client_id'),
// 'client_secret' => Config::get('oauth_client.client_secret'),
// 'redirect_uri' => Config::get('oauth_client.redirect_uri'),
// 'code' => $code,
// ],
// ]);
// return json_decode((string) $response->getBody(), true);
} catch (\Exception $e) {
dd($e); …Run Code Online (Sandbox Code Playgroud) 我已经使用 Laravel Passport 安装设置了一个新的 Laravel 5.6 安装。如果我使用 Postman向http://127.0.0.1/oauth/token发出帖子请求,我会得到一个有效的令牌:
要求
POST /oauth/token HTTP/1.1
Host: 127.0.0.1:8000
Content-Type: application/json
X-Requested-With: XMLHttpRequest
Cache-Control: no-cache
Postman-Token: 99529c07-0fe3-38a8-54cf-8b80a9dd5fbd
{
"grant_type" : "password",
"client_id" : 4,
"client_secret" : "Ib1UOS7BK12tFxOilqwea1XGJhrExbVYe8B7r8wK",
"username" : "mail@mail.com",
"password" : "password"
}
Run Code Online (Sandbox Code Playgroud)
回复:
{
"token_type": "Bearer",
"expires_in": 31536000,
"access_token": "eyJ0eXAiOiJKV1.....",
"refresh_token": "def5020026dfeb6f91f6a9....."
}
Run Code Online (Sandbox Code Playgroud)
我不希望我的用户直接访问它,所以我在 routes/web.php 文件中设置了一个路由:
Route::post('login', 'API\AuthController@login');
Run Code Online (Sandbox Code Playgroud)
我的 AuthController 看起来像:
<?php
namespace App\Http\Controllers\API;
use App\OAuth;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller as Controller;
use Illuminate\Support\Facades\Auth;
use Carbon\Carbon;
use App\User;
class AuthController extends …Run Code Online (Sandbox Code Playgroud)