PHP socket带验证的问题
Mad4U 2007-03-15 03:31:49 PHP的socket怎么返回需要密码验证才能访问的URL?
代码
-------------------------------------------------------
<?php
error_reporting(E_ALL);
/* Get the port for the WWW service. */
$service_port = "8181";
/* Get the IP address for the target host. */
$address = "xxx.xxx.xxx.xxx";
/* Create a TCP/IP socket. */
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket < 0) {
echo "socket_create() failed: reason: " . socket_strerror($socket) . "\n";
} else {
;
}
$result = socket_connect($socket, $address, $service_port);
if ($result < 0) {
echo "socket_connect() failed.\nReason: ($result) " . socket_strerror($result) . "\n";
} else {
;
}
$in = "GET /netbiz/services/netbiz?method=queryAcctAttrs&areaID=1&acctName=xxxxxxxx";
//$in .= getenv('REMOTE_ADDR');
$in .= " HTTP/1.1\r\n";
$in .= "Host: ";
$in .= $address;
$in .= "\r\n";
$in .= "Connection: Close\r\n\r\n";
$out = '';
socket_write($socket, $in, strlen($in));
$data = '';
while ($out = socket_read($socket, 2048))
{
$data .= $out;
}
socket_close($socket);
echo $data;
?>
-------------------------------------------------------
以上地址是有用户名和密码才能访问的
返回结果
-------------------------------------------------------
HTTP/1.1 401 Unauthorized
Server: Apache-Coyote/1.1
X-Powered-By: Servlet 2.4; JBoss-4.0.3SP1 (build: CVSTag=JBoss_4_0_3_SP1 date=200510231054)/Tomcat-5.5
WWW-Authenticate: Basic realm="AXIS"
Content-Type: text/xml;charset=ISO-8859-1
Content-Length: 551
Date: Thu, 15 Mar 2007 07:12:33 GMT
Connection: close
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode xmlns:ns1="http://xml.apache.org/axis/">ns1:Server.Unauthenticated</faultcode>
<faultstring>User 'null' not authenticated (unknown user)</faultstring>
<detail>
<ns2:hostname xmlns:ns2="http://xml.apache.org/axis/">xxx.xxx.xxxx.net</ns2:hostname>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
-------------------------------------------------------
问:怎么用socket来验证?
谢谢大家~~