{"record":{"id":"cea2ba9068c69b00","repo":"symfony/http-kernel","slug":"you-cannot-pass-non-empty-bodies-as-the-mime-component-is","errorCode":null,"errorMessage":"You cannot pass non-empty bodies as the Mime component is not installed. Try running \"composer require symfony/mime\".","messagePattern":"You cannot pass non-empty bodies as the Mime component is not installed\\. Try running \"composer require symfony/mime\"\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"HttpClientKernel.php","lineNumber":86,"sourceCode":"        try {\n            return new Response($response->getContent(!$catch), $response->getStatusCode(), $headers);\n        } catch (\\TypeError) {\n            // BC with Symfony < 8.1\n            $response = new Response($response->getContent(!$catch), $response->getStatusCode());\n            $response->headers = $headers;\n\n            return $response;\n        }\n    }\n\n    private function getBody(Request $request): ?AbstractPart\n    {\n        if (\\in_array($request->getMethod(), ['GET', 'HEAD'], true)) {\n            return null;\n        }\n\n        if (!class_exists(AbstractPart::class)) {\n            throw new \\LogicException('You cannot pass non-empty bodies as the Mime component is not installed. Try running \"composer require symfony/mime\".');\n        }\n\n        if ($content = $request->getContent()) {\n            return new TextPart($content, 'utf-8', 'plain', '8bit');\n        }\n\n        $fields = $request->request->all();\n        foreach ($request->files->all() as $name => $file) {\n            $fields[$name] = DataPart::fromPath($file->getPathname(), $file->getClientOriginalName(), $file->getClientMimeType());\n        }\n\n        return new FormDataPart($fields);\n    }\n\n    private function getHeaders(Request $request): array\n    {\n        $headers = [];\n        foreach ($request->headers as $key => $value) {","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/symfony/http-kernel/blob/aa3a39d7286a62cdfea98f0e69c651a3da6e36cf/HttpClientKernel.php#L68-L104","documentation":"HttpClientKernel::getBody() converts non-GET/HEAD request bodies into a Mime TextPart for the outgoing HTTP request. Converting a non-empty body requires symfony/mime (AbstractPart); without it, passing a non-empty body throws this LogicException.","triggerScenarios":"Sending a request with a non-empty body (POST/PUT/PATCH with content, or form data) through HttpClientKernel when symfony/mime is not installed. GET/HEAD requests are unaffected (return null).","commonSituations":"symfony/http-client installed but symfony/mime not pulled in as a dependency; minimal composer install that omits transitive requirements in older setups.","solutions":["Run composer require symfony/mime","Or send GET/HEAD requests only, or requests with empty bodies","Or provide the body as a pre-built AbstractPart yourself (still requires mime)"],"exampleFix":"// before (throws for POST with content)\n$client->request('POST', '/api', ['body' => 'data']);\n// after\ncomposer require symfony/mime\n$client->request('POST', '/api', ['body' => 'data']);","handlingStrategy":"validation","validationCode":"if ($request->getContent() !== '' && !class_exists(\\Symfony\\Component\\Mime\\Part\\AbstractPart::class)) {\n    throw new \\LogicException('symfony/mime required for non-empty bodies; run composer require symfony/mime');\n}\n$client->request($method, $uri, $options);","typeGuard":null,"tryCatchPattern":"try {\n    $client->request('POST', $uri, ['body' => $payload]);\n} catch (\\LogicException $e) {\n    $logger->error($e->getMessage());\n}","preventionTips":["composer require symfony/mime whenever symfony/http-client is used with request bodies","Avoid sending request bodies on GET/HEAD","Check composer.lock includes transitive mime dependency"],"tags":["http-client","missing-dependency","symfony"],"backgroundTag":"missing-optional-dependency","analyzedSha":"aa3a39d7286a62cdfea98f0e69c651a3da6e36cf","analyzedAt":"2026-09-13T18:03:36.509Z","contentChangedAt":"2026-09-13T18:03:36.509Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}