Chinaunix首页 | 论坛 | 博客
  • 博客访问: 556051
  • 博文数量: 34
  • 博客积分: 10171
  • 博客等级: 上将
  • 技术积分: 1365
  • 用 户 组: 普通用户
  • 注册时间: 2004-11-09 13:13
文章分类

全部博文(34)

文章存档

2011年(1)

2009年(20)

2008年(13)

我的朋友

分类:

2009-06-17 14:50:44

$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;
    }
?>

阅读(2188) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~