Laravel队列任务中使用Guzzle发起POST请求出现cURL解析错误
Hey there, let’s figure out why your queue tasks are throwing that cURL error 6. The core issue here is that all your Guzzle requests are somehow being directed to a host named router instead of the abc.com endpoint you’re specifying. Let’s break down the most likely causes and how to fix them:
1. Add the full protocol to your request URL
First off, notice your request uses abc.com/updateProduct without http:// or https://. Guzzle treats this as a relative path, which means if any base URI is set (accidentally or otherwise), it’ll append this path to that base. If the base URI is set to router, that’s exactly why you’re seeing the error.
Fix this by using the full URL in your request:
$response = $this->httpClient->request("POST", 'https://abc.com/updateProduct', $data);
If you suspect a stray base URI is being applied, you can explicitly disable it when creating your Guzzle client:
$config = [ 'verify' => false, 'timeout' => 30, 'headers' => ['Content-Type' => 'application/json'], 'base_uri' => null, // Ensure no base URI is used ]; $this->httpClient = new Client($config);
2. Check your queue worker’s environment configuration
Queue workers often run in a separate environment and cache config values. It’s possible your worker is loading a different .env file (like .env.queue) where an API base URL variable is set to router. For example, if your code uses something like env('API_BASE_URL') instead of the hardcoded abc.com, that’s a prime suspect.
- Double-check all environment variables related to API endpoints in your worker’s environment.
- Restart your queue worker after any config changes—workers don’t pick up new configs automatically:
php artisan queue:restart
3. Look for global HTTP client modifications
Laravel’s HTTP client (which wraps Guzzle) can be modified globally via service providers or macros. Check your App\Providers\AppServiceProvider.php (or other providers) for code that sets a global base URI:
// Example of problematic code use Illuminate\Support\Facades\Http; public function boot() { Http::globalOptions([ 'base_uri' => 'router', // This would override your URLs! ]); }
Even if you’re directly instantiating Client, some global configurations might leak through—so make sure no such overrides exist.
4. Debug the actual request being sent
To pinpoint exactly where the URL is getting changed, enable Guzzle’s debug mode to see the full request details:
$config = [ 'verify' => false, 'timeout' => 30, 'headers' => ['Content-Type' => 'application/json'], 'debug' => true, // This will print request logs to your console ]; $this->httpClient = new Client($config);
Alternatively, you can dump the full request URI before sending it:
$request = $this->httpClient->createRequest("POST", 'abc.com/updateProduct', $data); dd((string)$request->getUri()); // Prints the exact URL Guzzle will use
This will tell you if the URL is being altered in your code or by an external tool.
5. Check third-party tools or proxies
If you’re using service discovery tools, API gateways, or reverse proxies (like Nginx), they might be rewriting your request URLs to point to router internally. If your server can’t resolve the router hostname (no DNS entry or /etc/hosts mapping), you’ll get this error.
- Verify these tools aren’t modifying your request addresses incorrectly.
- If
routeris an internal service, add a mapping to your server’s/etc/hostsfile or configure internal DNS to resolve it.
内容的提问来源于stack exchange,提问作者Tiến Hưng

