gpt4 book ai didi

php - 使用 guzzle 向基于 laravel 的应用程序发送发布请求

转载 作者:行者123 更新时间:2023-11-29 03:20:57 24 4
gpt4 key购买 nike

我的本​​地主机中有 2 个 laravel 应用程序(用于测试目的)...我希望我的第一个 laravel 应用程序将 POST 数据发送到我的第二个 laravel 应用程序,然后将这些数据保存到 mysql 数据库。

所以这是我的第一个 laravel 应用程序路线

Route::get('post_request', function()
{

$client = new \GuzzleHttp\Client();
$url = "http://bkculv5.local/api_post";

$response = $client->post($url,[
'json'=>[
'judul' => 'title','content' => 'konten'
]]);

});

这是我的第二条 Laravel 应用路线

Route::post('/api_post', function(Request $request){
$judul = $request->judul;
$content = $request->content;

$artikel = new App\Artikel;
$artikel->judul = $judul;
$artikel->content = $content;

$artikel->save();
});

我得到的是

Server error: POST http://bkculv5.local/api_post resulted in a 500
Internal Server Error
response:

当我将 myfirstapplaravel.local/api_post 放入浏览器时

知道为什么吗?或者我是否需要像在 ajax 中使用 post 时那样使用 X-CSRF-TOKEN?

更新

这是我在 apache xampp 中的错误日志

[Thu Jul 20 15:26:35.201109 2017] [core:error] [pid 1500:tid 604] (EAI 11002)APR does not understand this error code: AH00549: Failed to resolve server name for 36.86.63.180 (check DNS) -- or specify an explicit ServerName
[Thu Jul 20 15:26:35.439807 2017] [ssl:warn] [pid 1500:tid 604] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Thu Jul 20 15:26:35.487845 2017] [mpm_winnt:notice] [pid 1500:tid 604] AH00354: Child: Starting 150 worker threads.

最佳答案

在 Windows 主机文件中添加你的 Laravel 应用程序 IP,也不要忘记 CORS。希望有所帮助。有时 https 也会导致问题,但他们的库中总是有 API 来跳过安全检查(仅用于开发目的)。

$client = new Guzzle\Http\Client();
$client->setDefaultOption('verify', '/path/to/cacert.pem');

或者,如果您需要禁用 SSL 验证:

$client->setDefaultOption('verify', false);

关于php - 使用 guzzle 向基于 laravel 的应用程序发送发布请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45209036/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com