php soap client 链接问题

1.说明
  php 调用jira的soap接口代码:
 
   <?php 
    $server_url = "http://******.44/s3c/samples/";
    $cur_url = "http://******.14/s3c/";

    // Jira WSDL
    $wsdl =  "http://******.14:8080/rpc/soap/jirasoapservice-v2?wsdl";
    $login = "******";
    $password = "******";
    try{
        $client = new soapclient($wsdl);
        $login = $client->login( $login,$password);
        $data = $_POST;
//        $userName = $_POST["sample_man"];
        $userName = 'xiaye';
        $sss = '';
        $count = 0;
        foreach($data as $key=>$value){
            if(strpos($key, 'items_')!==0){
                continue;
            }
            if($count == 0){
                $sss = str_replace('items_','',$key);
            }else{
                $sss .= '_'.str_replace('items_','',$key);
            }
            $count++;
        }
        
        $jsonurl = $server_url."issues_info.json?ids=".$sss;
        $json = file_get_contents($jsonurl,0,null,null);
        $json = json_decode($json, true);
        foreach($json as $s){
            $sample = $s['sample'];

            //样本文件
            $sampleFiles = $s['sampleFiles'];
            
            foreach($sampleFiles as $f){
                echo $f['SampleFile']['id'];
            }
            create_issue($client, $login, $userName, $sample, $sampleFiles, $server_url);
        }

        // Log out
        $logout = $client->logout($login);
        if($logout ==  TRUE){
        }else{
        }

        /* Redirect browser */
        header("Location: ".$cur_url);
        /* Make sure that code below does not get executed when we redirect. */
        exit;


        
    } catch (Exception $e) {
        print $e->getMessage();
        exit();
    }

    /**
     * 创建工单
     */
    function create_issue($client, $login, $userName, $sample, $sampleFiles, $server_url){
        try{
            //echo "TEST1!";
            //project key
            $project = "CHECKING";
            //issue type
            $type = 6;
            $date = date('Ymd');
            $detailUrl = "http://******.44/s3c/samples/view/";
            
            $filenames = ''; 
            foreach ( $sampleFiles as $sampleFile ) {
                $filenames .= $sampleFile['SampleFile']['ins_path']."\n ";
            }
                    
            
            $sampleName = date('Y-m-d',$sample['Sample']['report_at']/1000)."_".$sample['Sample']['id'].".sis";
            //a)    样本名称
            //b)    软件名称
            //c)    软件UID
            //d)    软件的证书颁发者
            //e)    软件的证书使用者
            //f)    样本中各个文件的安装路径
            //g)    样本详情链接
            $desc = "软件名称:".$sample['Sample']['name']."\n 软件UID:".$sample['Sample']['uid']."\n 软件的证书颁发者:".
                    $sample['Sample']['ca_issuer']."\n 软件的证书使用者:".$sample['Sample']['ca_subject'].
                    "\n样本中各个文件的安装路径:\n".$filenames."\n 样本详情链接:".
                    $detailUrl.$sample['Sample']['id'];
            $remoteIssue = array(array ("customfieldId"=>"customfield_10050", "values"=>array ($sampleName)),
                                array ("customfieldId"=>"customfield_10123", "values"=>array ($desc)),
                                array ("customfieldId"=>"customfield_10167", "values"=>array ("手机医生")));
            
            $issue = array(
                "project" => $project,
                "type" =>$type,
                "summary" => $date."_".date('Y-m-d',$sample['Sample']['report_at']/1000)."_".$sample['Sample']['id'].".sis",
                "assignee"=>$userName,
                "reporter"=>$login,
                "customFieldValues" => $remoteIssue
               );
                

            //  Create the Issue
            $result = $client->createIssue( $login,$issue);
            
            // Add attachment
            $attachment_file = $sample['Sample']['sis_path'];
            $jsonurl = $server_url."file_content.json?path=".$attachment_file;
            $json = file_get_contents($jsonurl,0,null,null);
            $attachmentName = basename($attachment_file);
            $result = $client->addBase64EncodedAttachmentsToIssue($login, $result->key, array($attachmentName), array(base64_encode($json)) );
            
            // Change status
            $jsonurl = $server_url."change_status.json?id=".$sample['Sample']['id'];
            $result = file_get_contents($jsonurl,0,null,null);
            //print_r($result);
        } catch (Exception $e) {
            print $e->getMessage();
            exit();
        }
    }
    
?>


2.出现错误
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://******.14:8080/rpc/soap/jirasoapservice-v2?wsdl' : failed to load external entity "http://******.14:8080/rpc/soap/jirasoapservice-v2?wsdl"

wsdl error: Getting http://******.14:8080/rpc/soap/jirasoapservice-v2?wsdl - HTTP ERROR: Couldn't open socket connection to server http://******.14:8080/rpc/soap/jirasoapservice-v2?wsdl, Error (13): Permission denied

3.解决问题
  出现此错误时,是因为httpd_can_network_connect 没有开通,通过命令打开即可。
  setsebool -P httpd_can_network_connect on

  备注:查看httpd的状态命令:/usr/sbin/getsebool -a | grep httpd
   
   allow_httpd_anon_write --> off
   allow_httpd_bugzilla_script_anon_write --> off
   allow_httpd_mod_auth_pam --> off
   allow_httpd_nagios_script_anon_write --> off
   allow_httpd_squid_script_anon_write --> off
   allow_httpd_sys_script_anon_write --> off
   httpd_builtin_scripting --> on
   httpd_can_network_connect --> off
   httpd_can_network_connect_db --> off
   httpd_can_network_relay --> off
   httpd_disable_trans --> off
   httpd_enable_cgi --> on
   httpd_enable_ftp_server --> off
   httpd_enable_homedirs --> on
   httpd_rotatelogs_disable_trans --> off
   httpd_ssi_exec --> off
   httpd_suexec_disable_trans --> off
   httpd_tty_comm --> on
   httpd_unified --> on        


4.相关链接
  http://www.linuxforums.org/forum/redhat-fedora-linux-help/46840-fsockopen-error-13-permission-denied.html(提到httpd错误)
  http://wiki.centos.org/zh/TipsAndTricks/SelinuxBooleans
  http://fedoraproject.org/wiki/SELinux/apache
  http://oss.tresys.com/docs/refpolicy/api/tunables.html

你可能感兴趣的:(PHP,json,linux,centos,SOAP)