From 4072046aaaa3b5db556262bb036439d45ee86e6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristia=CC=81n=20Feldsam?= Date: Fri, 2 Oct 2015 13:52:31 +0200 Subject: [PATCH] Fixed charset setting by refactored httpPost curl sending post body with content type. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kristián Feldsam --- src/Silverpop/EngagePod.php | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/Silverpop/EngagePod.php b/src/Silverpop/EngagePod.php index 85c9319..82a0e1f 100644 --- a/src/Silverpop/EngagePod.php +++ b/src/Silverpop/EngagePod.php @@ -793,11 +793,9 @@ private function _request($data, $replace = array(), $attribs = array()) { $xml = $data; } - $fields = array( - "jsessionid" => isset($this->_jsessionid) ? $this->_jsessionid : '', - "xml" => $xml, - ); - $response = $this->_httpPost($fields); + $jsessionid = isset($this->_jsessionid) ? $this->_jsessionid : ''; + + $response = $this->_httpPost($jsessionid, $xml); if ($response) { $arr = \Silverpop\Util\xml2array($response); if (isset($arr["Envelope"]["Body"]["RESULT"]["SUCCESS"])) { @@ -814,19 +812,19 @@ private function _request($data, $replace = array(), $attribs = array()) { * Private method: post the request to the url * */ - private function _httpPost($fields) { - $fields_string = http_build_query($fields); + private function _httpPost($jsessionid, $xml) { //open connection $ch = curl_init(); //set the url, number of POST vars, POST data - curl_setopt($ch,CURLOPT_HTTPHEADER, array('Expect:')); - curl_setopt($ch,CURLOPT_URL,$this->_getFullUrl()); - curl_setopt($ch,CURLOPT_POST,count($fields)); - curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string); + curl_setopt($ch,CURLOPT_HTTPHEADER, array('Expect:')); + curl_setopt($ch,CURLOPT_URL,$this->_getFullUrl().'?jsessionid='.$jsessionid); + curl_setopt($ch,CURLOPT_POSTFIELDS,$xml); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); - curl_setopt($ch,CURLOPT_HTTPHEADER,array ( - "Content-Type: application/x-www-form-urlencoded; charset=utf-8" )); + curl_setopt($ch,CURLOPT_HTTPHEADER, array( + 'Content-Type: text/xml;charset=UTF-8', + 'Content-Length: '.strlen($xml) + )); //execute post $result = curl_exec($ch);