2011-09-27 65 views
1

我使用curl做post请求,由于某种原因它打印xml响应,这是我不想发生的事情。我怎样才能摆脱这种行为?为什么curl打印XML响应?

/** 
* Send post request 
**/ 
function post_request($sendHttpUrl, $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; 
} 

回答

3

您已将RETURNTRANSFER标志设置在错误的变量上。更改$curl$ch

0

你要排队一个错字: “curl_setopt($卷曲,CURLOPT_RETURNTRANSFER,真正的);”

它应该阅读:

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);