Skip to content

Commit 5028174

Browse files
committed
Merge pull request #64 from erikverheij/fix/content-length-header
Set content-length header for put and post requests
2 parents 9e03f77 + ee723aa commit 5028174

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Google/Spreadsheet/DefaultServiceRequest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,12 @@ public function get($url)
140140
* @return string
141141
*/
142142
public function post($url, $postData)
143-
{
144-
$ch = $this->initRequest($url, array('Content-Type: application/atom+xml'));
143+
{
144+
$headers = array(
145+
'Content-Type: application/atom+xml',
146+
'Content-Length: ' . strlen($postData),
147+
);
148+
$ch = $this->initRequest($url, $headers);
145149
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
146150
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
147151
return $this->execute($ch);
@@ -157,7 +161,11 @@ public function post($url, $postData)
157161
*/
158162
public function put($url, $postData)
159163
{
160-
$ch = $this->initRequest($url, array('Content-Type: application/atom+xml'));
164+
$headers = array(
165+
'Content-Type: application/atom+xml',
166+
'Content-Length: ' . strlen($postData),
167+
);
168+
$ch = $this->initRequest($url, $headers);
161169
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
162170
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
163171
return $this->execute($ch);

0 commit comments

Comments
 (0)