0

I have two app in Laravel. One is simple api with one controller if i send params using online tool or postman app everything is ok. i need check in headers to send 'Host' without this header i got error 400 Bad Request. But if i try send the same from my second laravel app i've got empty params request

$response = Http::asForm()->withHeaders([
    'Host' => 'example.com:8091',
])->post('http://example.com:8091/abc/test/', [
     'param_1' => 'abcdefgh123',
     'param2' => 'blablabla',
]);

$body = $response->getBody()->getContents();

I tried asForm() and nothing. What should be in Host header ?

Wraith
  • 504
  • 6
  • 28

1 Answers1

0

Try this option

$json_data = json_encode(['param_1' => 'test 1', 'param_2' => 'test 2']);

$response = Http::asForm()->post('http://example.com:8091/abc/test/', [
    'body' => $json_data,
    'headers' => [
        'Content-Type' => 'application/json',
        'Content-Length' => strlen($json_data),
    ]
]);