Skip to content

Commit 0b52519

Browse files
author
Martin Brecht-Precht
committed
Updated readme.
1 parent ecf0d7c commit 0b52519

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,18 @@ $message
173173
->addCookie(new Cookie('PHPSESSID', '<MY_SESSION_ID>'))
174174
->setBody($messageBody);
175175
176+
// Please note, that headers have some unusual behaviours.
177+
// Header names have an uniform way of nomenclature so the three getter calls would have the same result.
178+
$header1 = $message->getHeaderByName('Content-Type');
179+
$header2 = $message->getHeaderByName('content-type');
180+
$header3 = $message->getHeaderByName('CONTENT-Type');
181+
182+
// To allow multiple request headers using the same name, the method `addAdditionalHeader` provides such a logic.
183+
// Add or replace a request header
184+
$message->addHeader(new Header('Custom-Header', array('CustomHeaderValue')));
185+
// Add a request header and keep the existing one untouched
186+
$message->addAdditionalHeader(new Header('Custom-Header', array('AnotherCustomHeaderValue')));
187+
176188
// Configuring and performing a Request
177189
$request = new Request();
178190
$response = $request
@@ -203,6 +215,8 @@ Cookie: PHPSESSID=<MY_SESSION_ID>
203215
Content-Type: application/json
204216
Accept: application/json, text/*
205217
Runscope-Bucket-Auth: 7a64dde7-74d5-4eed-b170-a2ab406eff08
218+
Custom-Header: CustomHeaderValue
219+
Custom-Header: AnotherCustomHeaderValue
206220
Content-Length: 102
207221
208222
{"paramName1":"paramValue1","paramName2":"paramValue2","paramName3":{"key1":"value1","key2":"value2"}}

detaild.php

+7
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@
4444
->addCookie(new Cookie('PHPSESSID', '<MY_SESSION_ID>'))
4545
->setBody($messageBody);
4646

47+
$header1 = $message->getHeaderByName('Content-Type');
48+
$header2 = $message->getHeaderByName('content-type');
49+
$header3 = $message->getHeaderByName('CONTENT-Type');
50+
51+
$message->addHeader(new Header('Custom-Header', array('CustomHeaderValue')));
52+
$message->addAdditionalHeader(new Header('Custom-Header', array('AnotherCustomHeaderValue')));
53+
4754
$request = new Request();
4855
$response = $request
4956
->setUserAgent('PHP Basic HTTP Client Test 1.0')

0 commit comments

Comments
 (0)