
SwooleCoroutineHttpClient::setData 메서드는 요청 본문(content)과 헤더(header)를 함께 전달할 수 있습니다.
setData 메서드의 파라미터 중 'data'와 'header'를 구별하여 전달하는 방법은 다음과 같습니다.
#hostingforum.kr
php
$client = new SwooleCoroutineHttpClient('http://example.com');
$client->setData([
'header' => [
'Content-Type' => 'application/json',
],
'data' => [
'key' => 'value',
],
]);
위 예제에서 'header' 파라미터는 요청 헤더를, 'data' 파라미터는 요청 본문을 지정합니다.
또한, setData 메서드의 파라미터는 배열 형식으로 전달할 수 있습니다.
#hostingforum.kr
php
$client = new SwooleCoroutineHttpClient('http://example.com');
$client->setData([
'header' => [
'Content-Type' => 'application/json',
],
'data' => [
'key' => 'value',
],
'method' => 'POST',
]);
위 예제에서 'method' 파라미터는 요청 메서드를 지정합니다.
setData 메서드를 호출할 때, 요청 본문(content)과 헤더(header)를 함께 전달할 수 있습니다.
#hostingforum.kr
php
$client = new SwooleCoroutineHttpClient('http://example.com');
$client->setData([
'header' => [
'Content-Type' => 'application/json',
],
'data' => [
'key' => 'value',
],
'method' => 'POST',
]);
$client->start();
위 예제에서 setData 메서드를 호출하고, start 메서드를 호출하여 요청을 전송합니다.
이러한 방법으로 setData 메서드를 사용하여 HTTP 요청을 보내실 수 있습니다.
2025-04-30 14:44