Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflicting content type headers in request and request body #374

Open
mtalaeii opened this issue Jan 15, 2025 · 2 comments
Open

Conflicting content type headers in request and request body #374

mtalaeii opened this issue Jan 15, 2025 · 2 comments

Comments

@mtalaeii
Copy link

Code

$form = new Form;
$form->addField(...);
$form->addField(...);
$request = new Request("https://example.com","POST");
$request->setBody($form);
$request->setHeader( "Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
print($client->request($request)->getBody()->buffer());

Trace

PHP Fatal error:  Uncaught Amp\Http\Client\HttpException: Conflicting content type headers in request and request body: application/x-www-form-urlencoded;charset=UTF-8 / application/x-www-form-urlencoded in /home/Mahdi/test/vendor/amphp/http-client/src/Connection/Internal/RequestNormalizer.php:42
Stack trace:
#0 /home/Mahdi/test/vendor/amphp/http-client/src/Connection/Internal/RequestNormalizer.php(23): Amp\Http\Client\Connection\Internal\RequestNormalizer::normalizeRequestBodyHeaders()
#1 /home/Mahdi/test/vendor/amphp/http-client/src/Connection/Http1Connection.php(222): Amp\Http\Client\Connection\Internal\RequestNormalizer::normalizeRequest()
#2 /home/Mahdi/test/vendor/amphp/http-client/src/Connection/HttpStream.php(96): Amp\Http\Client\Connection\Http1Connection->request()
#3 /home/Mahdi/test/vendor/amphp/http-client/src/functions.php(20): Amp\Http\Client\Connection\HttpStream->Amp\Http\Client\Connection\{closure}()
#4 /home/Mahdi/test/vendor/amphp/http-client/src/Connection/HttpStream.php(96): Amp\Http\Client\processRequest()
#5 /home/Mahdi/test/vendor/amphp/http-client/src/Connection/ConnectionLimitingPool.php(131): Amp\Http\Client\Connection\HttpStream->request()
#6 /home/Mahdi/test/vendor/amphp/http-client/src/Connection/HttpStream.php(96): Amp\Http\Client\Connection\ConnectionLimitingPool->Amp\Http\Client\Connection\{closure}()
#7 /home/Mahdi/test/vendor/amphp/http-client/src/functions.php(20): Amp\Http\Client\Connection\HttpStream->Amp\Http\Client\Connection\{closure}()
#8 /home/Mahdi/test/vendor/amphp/http-client/src/Connection/HttpStream.php(96): Amp\Http\Client\processRequest()
#9 /home/Mahdi/test/vendor/amphp/http-client/src/Interceptor/DecompressResponse.php(43): Amp\Http\Client\Connection\HttpStream->request()
#10 /home/Mahdi/test/vendor/amphp/http-client/src/Connection/InterceptedStream.php(53): Amp\Http\Client\Interceptor\DecompressResponse->requestViaNetwork()
#11 /home/Mahdi/test/vendor/amphp/http-client/src/functions.php(20): Amp\Http\Client\Connection\InterceptedStream->Amp\Http\Client\Connection\{closure}()
#12 /home/Mahdi/test/vendor/amphp/http-client/src/Connection/InterceptedStream.php(36): Amp\Http\Client\processRequest()
#13 /home/Mahdi/test/vendor/amphp/http-client/src/Interceptor/ModifyRequest.php(36): Amp\Http\Client\Connection\InterceptedStream->request()
#14 /home/Mahdi/test/vendor/amphp/http-client/src/Connection/InterceptedStream.php(53): Amp\Http\Client\Interceptor\ModifyRequest->requestViaNetwork()
#15 /home/Mahdi/test/vendor/amphp/http-client/src/functions.php(20): Amp\Http\Client\Connection\InterceptedStream->Amp\Http\Client\Connection\{closure}()
#16 /home/Mahdi/test/vendor/amphp/http-client/src/Connection/InterceptedStream.php(36): Amp\Http\Client\processRequest()
#17 /home/Mahdi/test/vendor/amphp/http-client/src/Interceptor/ModifyRequest.php(36): Amp\Http\Client\Connection\InterceptedStream->request()
#18 /home/Mahdi/test/vendor/amphp/http-client/src/Connection/InterceptedStream.php(53): Amp\Http\Client\Interceptor\ModifyRequest->requestViaNetwork()
#19 /home/Mahdi/test/vendor/amphp/http-client/src/functions.php(20): Amp\Http\Client\Connection\InterceptedStream->Amp\Http\Client\Connection\{closure}()
#20 /home/Mahdi/test/vendor/amphp/http-client/src/Connection/InterceptedStream.php(36): Amp\Http\Client\processRequest()
#21 /home/Mahdi/test/vendor/amphp/http-client/src/PooledHttpClient.php(36): Amp\Http\Client\Connection\InterceptedStream->request()
#22 /home/Mahdi/test/vendor/amphp/http-client/src/functions.php(30): Amp\Http\Client\PooledHttpClient->Amp\Http\Client\{closure}()
#23 /home/Mahdi/test/vendor/amphp/http-client/src/PooledHttpClient.php(29): Amp\Http\Client\processRequest()
#24 /home/Mahdi/test/vendor/amphp/http-client/src/Interceptor/RetryRequests.php(34): Amp\Http\Client\PooledHttpClient->request()
#25 /home/Mahdi/test/vendor/amphp/http-client/src/InterceptedHttpClient.php(38): Amp\Http\Client\Interceptor\RetryRequests->request()
#26 /home/Mahdi/test/vendor/amphp/http-client/src/functions.php(20): Amp\Http\Client\InterceptedHttpClient->Amp\Http\Client\{closure}()
#27 /home/Mahdi/test/vendor/amphp/http-client/src/InterceptedHttpClient.php(28): Amp\Http\Client\processRequest()
#28 /home/Mahdi/test/vendor/amphp/http-client/src/Interceptor/FollowRedirects.php(131): Amp\Http\Client\InterceptedHttpClient->request()
#29 /home/Mahdi/test/vendor/amphp/http-client/src/InterceptedHttpClient.php(38): Amp\Http\Client\Interceptor\FollowRedirects->request()
#30 /home/Mahdi/test/vendor/amphp/http-client/src/functions.php(20): Amp\Http\Client\InterceptedHttpClient->Amp\Http\Client\{closure}()
#31 /home/Mahdi/test/vendor/amphp/http-client/src/InterceptedHttpClient.php(28): Amp\Http\Client\processRequest()
#32 /home/Mahdi/test/vendor/amphp/http-client/src/Interceptor/ModifyRequest.php(48): Amp\Http\Client\InterceptedHttpClient->request()
#33 /home/Mahdi/test/vendor/amphp/http-client/src/InterceptedHttpClient.php(38): Amp\Http\Client\Interceptor\ModifyRequest->request()
#34 /home/Mahdi/test/vendor/amphp/http-client/src/functions.php(20): Amp\Http\Client\InterceptedHttpClient->Amp\Http\Client\{closure}()
#35 /home/Mahdi/test/vendor/amphp/http-client/src/InterceptedHttpClient.php(28): Amp\Http\Client\processRequest()
#36 /home/Mahdi/test/vendor/amphp/http-client/src/HttpClient.php(33): Amp\Http\Client\InterceptedHttpClient->request()
#37 /home/Mahdi/test/vendor/amphp/http-client/src/functions.php(30): Amp\Http\Client\HttpClient->Amp\Http\Client\{closure}()
#38 /home/Mahdi/test/vendor/amphp/http-client/src/HttpClient.php(30): Amp\Http\Client\processRequest()
#39 /home/Mahdi/test/test.php(60): Amp\Http\Client\HttpClient->request()
#40 {main}
  thrown in /home/Mahdi/test/vendor/amphp/http-client/src/Connection/Internal/RequestNormalizer.php on line 42
@kelunik
Copy link
Member

kelunik commented Jan 16, 2025

Avoid manually setting the header.

@mtalaeii
Copy link
Author

mtalaeii commented Jan 19, 2025

The problem here is header is the same header for sending form-encoded request just have charset=UTF-8
Can't add the support from that? or maybe i'm doing it in wrong way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants