doumie6223
2013-08-05 13:04
浏览 683
已采纳

curl_exec返回空白,没有错误

I make a curl call which seems to go fine.

[http_code] => 200, and curl_errno is 0.

Yet despite the fact there should be an output ([download_content_length] => 102), the curl_exec call doesn't return anything.

define('_WSURL', 'https://mobistar.msgsend.com/mmp/cp3'); // Feel free to try it yourself

$stderr = fopen("err.log", 'w+');
if ($stderr !== false) {
  print "Opened the log file without errors";
}

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, _WSURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, '');
// curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_STDERR, $stderr);
// curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).DIRECTORY_SEPERATOR.'c00kie.txt'); 

$data = curl_exec($ch);

fclose($stderr);

print_r(curl_getinfo($ch));

print_r($data);

if ($data === false)
{ // Process curl error codes here
    echo('ERROR');
    echo(curl_errno($ch));
} else {
    echo(sprintf('DATA: [%s]', $data));
}
curl_close($ch);

How comes?

图片转代码服务由CSDN问答提供 功能建议

我做了一个看起来很好的卷曲调用。

[http_code] => 200 curl_errno 为0。

尽管事实上应该有一个输出( [download_content_length] =&gt; 102 < / code>),curl_exec调用不返回任何内容。

  define('_ WSURL','https://mobistar.msgsend.com/mmp/cp3')  ;  //随意自己尝试
 
 $ stderr = fopen(“err.log”,“w +”); 
if($ stderr!== false){
 print“打开日志文件时没有错误”  ; 
} 
 
 $ ch = curl_init(); 
curl_setopt($ ch,CURLOPT_URL,_WSURL); 
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,true); 
curl_setopt($ ch,CURLOPT_HEADER,false); 
curl_setopt  ($ ch,CURLOPT_POST,1); 
curl_setopt($ ch,CURLOPT_POSTFIELDS,''); 
 // curl_setopt($ ch,CURLOPT_POSTFIELDS,$ xml); 
curl_setopt($ ch,CURLOPT_SSL_VERIFYPEER,false); 
curl_setopt(  $ ch,CURLOPT_FOLLOWLOCATION,true); 
curl_setopt($ ch,CURLOPT_VERBOSE,true); 
curl_setopt($ ch,CURLOPT_STDERR,$ stderr); 
 // curl_setopt($ ch,CURLOPT_COOKIEJAR,dirname(__ FILE __)。DIRECTORY_SEPERATOR。'  c00kie.txt');  
 
 $ data = curl_exec($ ch); 
 
 nclclose($ stderr); 
 
print_r(curl_getinfo($ ch)); 
 
print_r($ data); 
 
if($ data  === false)
 {//在此处理卷曲错误代码
 echo('ERROR'); 
 echo(curl_errno($ ch)); 
} else {
 echo(sprintf('DATA:[  %s]',$ data)); 
} 
 ncl_close($ ch); 
   
 
 

怎么来的?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douliao7930 2013-08-05 13:56
    已采纳

    Returns a response for me.

    <?xml version="1.0" encoding="UTF-8"?>
    <response code="499" description="The XML Content is Invalid"/>
    

    I suspect you're seeing a blank page in your browser. If it's so, take a look at the page source in the browser, the XML should be there.

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • donglu9445 2013-08-05 14:19

    Arg, I'm so stupid sometimes...

    The response is a XML and I tried to output it directly in the HTML, but of course it's just considered a set of invalid tags thus display as blank.
    I should have taken a closer look to the source code XD

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题