开发者

Why curl prints XML response?

I'm using curl to do post request, for some reason it prints xml response, which is something that I don't want to happend. how can I get rid of this behaviour?

/**
*   Send post request
**/
function post_request($sendHtt开发者_C百科pUrl, $data) {

    $ch = curl_init($sendHttpUrl);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));      
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);       
    $response = curl_exec($ch);
    curl_close($ch);

    return $response;
}


You've set the RETURNTRANSFER flag on the wrong variable. Alter $curl to $ch.


You have a typo in line: "curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); "

It should read:

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜