Skip to content

Commit 4072046

Browse files
committed
Fixed charset setting by refactored httpPost curl sending post body with content type.
Signed-off-by: Kristián Feldsam <[email protected]>
1 parent fb1d477 commit 4072046

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/Silverpop/EngagePod.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -793,11 +793,9 @@ private function _request($data, $replace = array(), $attribs = array()) {
793793
$xml = $data;
794794
}
795795

796-
$fields = array(
797-
"jsessionid" => isset($this->_jsessionid) ? $this->_jsessionid : '',
798-
"xml" => $xml,
799-
);
800-
$response = $this->_httpPost($fields);
796+
$jsessionid = isset($this->_jsessionid) ? $this->_jsessionid : '';
797+
798+
$response = $this->_httpPost($jsessionid, $xml);
801799
if ($response) {
802800
$arr = \Silverpop\Util\xml2array($response);
803801
if (isset($arr["Envelope"]["Body"]["RESULT"]["SUCCESS"])) {
@@ -814,19 +812,19 @@ private function _request($data, $replace = array(), $attribs = array()) {
814812
* Private method: post the request to the url
815813
*
816814
*/
817-
private function _httpPost($fields) {
818-
$fields_string = http_build_query($fields);
815+
private function _httpPost($jsessionid, $xml) {
819816
//open connection
820817
$ch = curl_init();
821818

822819
//set the url, number of POST vars, POST data
823-
curl_setopt($ch,CURLOPT_HTTPHEADER, array('Expect:'));
824-
curl_setopt($ch,CURLOPT_URL,$this->_getFullUrl());
825-
curl_setopt($ch,CURLOPT_POST,count($fields));
826-
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
820+
curl_setopt($ch,CURLOPT_HTTPHEADER, array('Expect:'));
821+
curl_setopt($ch,CURLOPT_URL,$this->_getFullUrl().'?jsessionid='.$jsessionid);
822+
curl_setopt($ch,CURLOPT_POSTFIELDS,$xml);
827823
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
828-
curl_setopt($ch,CURLOPT_HTTPHEADER,array (
829-
"Content-Type: application/x-www-form-urlencoded; charset=utf-8" ));
824+
curl_setopt($ch,CURLOPT_HTTPHEADER, array(
825+
'Content-Type: text/xml;charset=UTF-8',
826+
'Content-Length: '.strlen($xml)
827+
));
830828

831829
//execute post
832830
$result = curl_exec($ch);

0 commit comments

Comments
 (0)