I am trying to request web page by POST via yii\httpclient\Client
(Currently page I request belong to same site I sending request from, but it will change later)
How it should work: I send AJAX POST to page /api/request-acceptor-open, script on that page sends POST with some data to /api/c-request-acceptor-open
Yii is running as Test Server ( yii serve from folder @app/tests/bin)
How I create request:
$client = new Client([ 'baseUrl' => $addressToSend, 'requestConfig' => ['format' => Client::FORMAT_JSON], 'responseConfig' => ['format' => Client::FORMAT_JSON] ]); $response = $client->createRequest() ->addHeaders(['content-type' => 'application/json']) ->setOptions([ 'timeout' => \Yii::$app->params['httpTimeout'] ?? 10, ]) ->setMethod('POST') ->setContent( json_encode($data) ) ->send();
When I run this code as it should be,
$addressToSend = 'http://localhost:8080/api/c-request-acceptor-open'
, i receive error
"Cannot send confirmation: fopen(http://localhost:8080/api/c-request-acceptor-open): failed to open stream: HTTP request failed!"
Without timeout restricitions
Operation timed out after 30000 ms with 0 bytes received
Server access log looks like
[Thu Apr 15 19:32:55 2021] PHP 7.4.12 Development Server (http://localhost:8080) started [Thu Apr 15 19:32:58 2021] 127.0.0.1:40948 Accepted [Thu Apr 15 19:32:58 2021] 127.0.0.1:40948  POST /api/request-acceptor-open [Thu Apr 15 19:32:58 2021] 127.0.0.1:40948 Closing [Thu Apr 15 19:32:58 2021] 127.0.0.1:40950 Accepted [Thu Apr 15 19:33:08 2021] 127.0.0.1:40950  POST /api/request-acceptor-open [Thu Apr 15 19:33:08 2021] 127.0.0.1:40950 Closing [Thu Apr 15 19:33:08 2021] 127.0.0.1:40952 Accepted [Thu Apr 15 19:33:08 2021] 127.0.0.1:40952  POST /api/c-request-acceptor-open [Thu Apr 15 19:33:08 2021] 127.0.0.1:40952 Closing
If I visit this page http://localhost:8080/api/c-request-acceptor-open via any browser, it works fine.
When I set address as test domain
$addressToSend = 'http://wash/api/c-request-acceptor-open'
$addressToSend = 'http://wash:80/api/c-request-acceptor-open'
I receive correct answer and everything work ok.
Why is it happening?
Will be grateful for any help. Thank you.