谢谢解答,我照着你的代码改了改,结果出错了。 错误原因是:Server was unable to process request. ---> Name cannot begin with the '<' character, hexadecimal value 0x3C. Line 1, position 2. 能不能帮忙看下错在哪,我觉得变量的名字没问题啊代码如下 $username='wanger'; $password='123456abc!'; $ToITPhoneNo='00653218569745';
用csdn的webservice当例子.
调用方法的格式说明在这里
http://forum.csdn.net/OpenApi/forumapi.asmx?op=GetUserProfile
$user = '你的csdn帐号';
$pass = '帐号密码';
$friend = '你的csdn帐号';//要查询的帐号
$fn = fsockopen('forum.csdn.net',80,$errstr,$errno,1);
if(!$fn)
{
exit($errstr);
}
$post = <<<POST
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetUserProfile xmlns="http://www.csdn.net/">
<identity>
<username>{$user}</username>
<password>{$pass}</password>
</identity>
<username>{$friend}</username>
</GetUserProfile>
</soap:Body>
</soap:Envelope>
POST;
fwrite($fn,"POST /OpenApi/forumapi.asmx HTTP/1.1\r\n");
fwrite($fn,"Host: forum.csdn.net\r\n");
fwrite($fn,"Content-Type: text/xml; charset=utf-8\r\n");
fwrite($fn,"Connection:close\r\n");
fwrite($fn,"Content-Length:".strlen($post)."\r\n\r\n");
fwrite($fn,$post);
while(!feof($fn))
{
$return .= fgets($fn,1024);
}
fclose($fn);
echo "<xmp>".$return."</xmp>";//帐户的信息,xml格式
错误原因是:Server was unable to process request. ---> Name cannot begin with the '<' character, hexadecimal value 0x3C. Line 1, position 2.
能不能帮忙看下错在哪,我觉得变量的名字没问题啊代码如下
$username='wanger';
$password='123456abc!';
$ToITPhoneNo='00653218569745';
$fn = fsockopen('www.internettelecom.com.sg',80,$errstr,$errno,1);
if(!$fn)
{
exit($errstr);
}
$post = "<<
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">
<soap:Body>
<GetLogin xmlns=\"http://www.internettelecom.com.sg/IPhoneWS/\">
<UserName>".$username."</UserName>
<Password>".$password."</Password>
<ToITPhoneNo>".$ToITPhoneNo."</ToITPhoneNo>
</GetLogin>
</soap:Body>
</soap:Envelope>"; fwrite($fn,"POST /IPhoneWS/IPhoneWebService.asmx HTTP/1.1\r\n");
fwrite($fn,"Host: www.internettelecom.com.sg\r\n");
fwrite($fn,"Content-Type: text/xml; charset=utf-8\r\n");
fwrite($fn,"Connection:close\r\n");
fwrite($fn,"Content-Length:".strlen($post)."\r\n\r\n");
fwrite($fn,$post);
while(!feof($fn))
{
$return .= fgets($fn,1024);
}
fclose($fn);
echo "<xmp>".$return."</xmp>";
$password='123456abc!';
$ToITPhoneNo='00653218569745'; $fn = fsockopen('www.internettelecom.com.sg',80,$errstr,$errno,1);
if(!$fn)
{
exit($errstr);
}
//你的$post = "<<...";明显是有问题的.
$post = <<<POST
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetLogin xmlns="http://www.internettelecom.com.sg/IPhoneWS/">
<UserName>{$username}</UserName>
<Password>{$password}</Password>
<ToITPhoneNo>{$ToITPhoneNo}</ToITPhoneNo>
</GetLogin>
</soap:Body>
</soap:Envelope>
POST;
fwrite($fn,"POST /IPhoneWS/IPhoneWebService.asmx HTTP/1.1\r\n");
fwrite($fn,"Host: www.internettelecom.com.sg\r\n");
fwrite($fn,"Content-Type: text/xml; charset=utf-8\r\n");
fwrite($fn,"Connection:close\r\n");
fwrite($fn,"Content-Length:".strlen($post)."\r\n\r\n");
fwrite($fn,$post);
while(!feof($fn))
{
$return .= fgets($fn,1024);
}
fclose($fn);
echo "<xmp>".$return."</xmp>";
按照以上代码,可以返回GetLoginResponse,接下来是你调用方法的参数问题,自己去查使用手册,或者问webservice的提供商
http response :HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Mon, 17 May 2010 10:52:24 GMT
X-Powered-By: ASP.NET
Connection: close
X-AspNet-Version: 2.0.50727
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Content-Length: 373<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetLoginResponse xmlns="http://www.internettelecom.com.sg/IPhoneWS/"><GetLoginResult>err02</GetLoginResult></GetLoginResponse></soap:Body></soap:Envelope>
$xml = new DOMDocument();
$xml->load($rs);
$envelope = $xml->getElementsByTagName( "soap:Envelope" );$body = $envelope->getElementsByTagName( "soap:Body" );
$GetLoginResponse = $body->getElementsByTagName( "GetLoginResponse" );$GetLoginResult = $GetLoginResponse->getElementsByTagName( "GetLoginResult" );if( strcmp($GetLoginResult,"err02")==0 ){
echo "00000000000";
}else{
echo "11111111111";
}