开发者

Curl Request damages XML Post Data

开发者 https://www.devze.com 2023-04-13 09:52 出处:网络
I am sending XML data as a POST request with curl to server as follows: // $params contains xslt=\"<xml version ....\"

I am sending XML data as a POST request with curl to server as follows:

    // $params contains xslt="<xml version ...."
    $url = get_cfg_var('Http_Host') . "/webservice/update.php?";
    $strParameters = http_build_query($params);

    $ch = curl_init($url);
    // Set options
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $strParameters);
    $data = curl_exec($ch);

Now when I get the data in webserive/update.php

$_REQUEST['xslt'] contains only some leaf data from xml with most of the tags stripped out like so [but with a lot of new lines]

 USD

  开发者_JAVA技巧,
  .


  0 
  5

I am at a loss to understand what is happening. Is it some double encoding issue?

strParameters does contain proper data in form-urlencoded format [+ for space etc.]

I tried a urldecode before sending it to curl. but it still doesn't solve the issue.


This is more a comment than a concrete solution, but I would consider to use the array method instead of encoding your own:

You don't need to encode the post-data yourself. You can directly use an array, see:

CURLOPT_POSTFIELDS The full data to post in a HTTP "POST" operation. [...] This parameter can either be passed as a urlencoded string like 'para1=val1&para2=val2&...' *or as an array with the field name as key and field data as value. If value is an array, the Content-Type header will be set to multipart/form-data.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号