卷曲无法在同一台服务器上获得响应

时间:2014-12-31 06:52:21

标签: php web-services curl yii

我在我的应用程序中使用curl。

我在DefaultController中的功能:

public function actionWebServices()
{

    $data = array("account" => "1234", "dob" => "30051987", "site" => "mytestsite.com");
    $fields='';
    foreach ($data as $key => $value) 
        {
            $fields .= $key . '/' . $value . '/';
        }
    rtrim($fields, '&');

    $u='admin';
    $p='admin123';
    $url='localhost:83/Working-copy/mysite/ServiceTypeMaster/Test';

     $ch = curl_init($url);
     curl_setopt($ch, CURLOPT_HEADER, 1);  
     curl_setopt($ch, CURLOPT_POST, 1);  
     curl_setopt($ch, CURLOPT_VERBOSE, 1);  
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);  
     curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);    
     curl_setopt($ch, CURLINFO_HEADER_OUT, 1); 
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
     curl_setopt($ch, CURLOPT_USERPWD, $u.':'.$p);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_POST, count($data));
     curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

     session_write_close();

     $result = curl_exec($ch);

     curl_close($ch);

     session_start();

     return $result;

}

serviceTypeMasterController

public function actionTest()
{
    echo "test";
}

我在curl网址中调用localhost的网址。但卷曲没有给出任何回应。它只给我Response Doesn't contain any data

有什么问题?

1 个答案:

答案 0 :(得分:0)

通常,该响应是指页面/服务不存在。你确定你在端口83上运行你的服务器(而不是默认的80)并且url解析为你的actionTest(而不是test)方法吗?