php Guzzle 返回 cURL 错误 3:<url> 格式错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29722822/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:32:13  来源:igfitidea点击:

Guzzle returns cURL error 3: <url> malformed

phplaravelcurlguzzle

提问by LoveAndHappiness

I want to try out the guzzle library and am following through their quickstarttutorial to make http requests to an api.

我想试用 guzzle 库,并按照他们的快速入门教程向 api 发出 http 请求。

Yet it doesn't seem to work, because I get the following error:

但它似乎不起作用,因为我收到以下错误:

cURL error 3: <url> malformed

Since I have never worked with cURL before, I don't even know how to respond to that error message. Here is my code with the request I am making:

由于我以前从未使用过 cURL,因此我什至不知道如何响应该错误消息。这是我提出的请求的代码:

    $client = new Client();
    $client->get('/', ['verify' => true]);

    $response = $client->get('https://api.github.com/');

    dd($response);

I am using the Laravel 5 framework and calling the index method in my HomeController. Also am using WAMP.

我正在使用 Laravel 5 框架并在我的 HomeController 中调用 index 方法。也正在使用 WAMP。

I would appreciate any help and suggestion, because I would like to try Guzzle out.

我很感激任何帮助和建议,因为我想尝试 Guzzle。

Here is a picture of the Error Message I get:

这是我收到的错误消息的图片:

Laravel 5 Error Message

Laravel 5 错误信息

采纳答案by Limon Monte

If you want to disable verification (don't do this!):

如果您想禁用验证(不要这样做!):

$response = $client->get('https://api.github.com/', ['verify' => false]);

Rather than disabling verification entirely, this can likely be fixed by providing proper CA bundle file. See verifyin Guzzle documentation.

这可以通过提供适当的 CA 包文件来解决,而不是完全禁用验证。请参阅verifyGuzzle 文档。

$client->setDefaultOption(
    'verify', 
    'C:\Program Files (x86)\Git\bin\curl-ca-bundle.crt'
);

回答by Teliov

You should not have this call:

你不应该有这个电话:

$client->get('/', ['verify' => true]);

That is what is throwing the error. The third line is okay.

这就是抛出错误的原因。第三行没问题。

The error is means what it says. The url is malformed. In my case on initialization of the Client, I used base_urlinstead of base_uri. So if you run into this error make sure your url is properly specified.

错误就是它所说的意思。网址格式不正确。在我的客户端初始化案例中,我使用了base_url而不是base_uri。因此,如果您遇到此错误,请确保正确指定了您的 url。

回答by Kaizoku Gambare

In case you came here because you googled "Guzzle returns cURL error 3: malformed" check the client parameter. In some version it's base_uriand other base_url

如果您是因为搜索“Guzzle 返回 cURL 错误 3:格式错误”而来到这里的,请检查客户端参数。在某些版本中它是base_uri和其他base_url

    $client = new Client([
        'base_uri' => 'http://localhost:8000',  // <-- base_uri instead of base_url
    ]);