免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2118 | 回复: 0

php soap方式发送 [复制链接]

论坛徽章:
0
发表于 2009-06-17 14:50 |显示全部楼层

$xml.="lu*lu*digico";
//soap 发送
$ret_str = Socket_Connect_HTTP_Post("发送目标IP或域名", "80", "目标文件路径", "目标文件", $xml); //$xml 数据包

//返回结果XML解析
$ret_str=str_replace(" ","",$ret_str);
$p = xml_parser_create();
xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 1);
xml_parse_into_struct($p,$ret_str,$vals,$index);
xml_parser_free($p);

?
    function Socket_Connect_HTTP_Post($server, $port, $dir, $file, $data)
    {
        if ((substr($dir, -1) != "/") && (substr($file, 0, 1) != "/"))
        {
            $dir .= "/";
        }
        $send_url = str_replace("%2F", "/", rawurlencode(rawurldecode(urldecode($dir . $file))));
        $method = "POST";
        $http_header_array["ALL"][] = "Accept: */*";
        $http_header_array["ALL"][] = "Referer: http://".$server."/";
        $http_header_array["ALL"][] = "Accept-Language: en-us,zh-cn";
        $http_header_array["ALL"][] = "---------------: ----- -------";
        $http_header_array["ALL"][] = "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
        $http_header_array["ALL"][] = "Connection: Keep-Alive";
        $http_header_array["ALL"][] = "Host: ".$server;
        $http_header_array["ALL"][] = "urn:po-processor";
/*
//        $http_header_array["ALL"][] = "Cookie: ";
//        $http_header_array["GET"][] = "If-Modified-Since: Wed, 17 Dec 2003 11:31:54 GMT";
//        $http_header_array["GET"][] = "If-None-Match: 10f047-5b2-3fe03eaa";
*/
        $http_header_array["POST"][] = "Cache-Control: no-cache";
        $http_header_array["POST"][] = "Content-Type: text/xml";  //数据XML格式
        $http_header_array["POST"][] = "Content-Length: ".strlen($data);
       // echo "####################################".$data;
        if (is_array($http_header_array["ALL"]))
        {
            $http_header_str_all = implode("\r\n", $http_header_array["ALL"]);
        }
        if (is_array($http_header_array[$method]))
        {
            $http_header_str_all .= "\r\n".implode("\r\n", $http_header_array[$method]);
        }
        $send_all = "POST ".$send_url." HTTP/1.1\r\n".$http_header_str_all."\r\n\r\n";
        $send_all .= $data."\r\n\r\n";
//        echo "2: ".nl2br($send_all."\n\n\n");
        $fp_send = @fsockopen($server, $port, $errno, $errstr ,30);
//        $times_open++;
        if ($fp_send)
        {
            $can_rcv = 0;
            fputs($fp_send, $send_all);
            stream_set_timeout($fp_send, 120);
            while(!feof($fp_send))
            {
                $content_t = fgets($fp_send, 1024);
                if ((trim($content_t) == "") && !$can_rcv)
                {
                    $can_rcv = 1;
                    $content_t = fgets($fp_send, 1024);
                    //echo $content_t ."@@@@@@@@@@@@@@@\n";
                }
               
                if ($can_rcv == 1 and strlen($content_t)>5)
                {
                    $reply_str .= $content_t;
                }
                //echo "**".$content_t."@@".$can_rcv."&&".$reply_str."\n";
            }
            $stream_status = stream_get_meta_data($fp_send);
            fclose($fp_send);
            if ($stream_status[timed_out])
            {
                $reply_str = "";
            }
        }
        return $reply_str;
    }
?>


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/1184/showart_1967199.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP