无论我做什么,我都会遇到同样的错误。错误是"缺少身份验证标头!无法进行身份验证!"
以下是根据我的请求生成的xml:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="xxxx" xmlns:ns2="xxxx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Header>
<ns2:ApiAuthentication>
<LoginName>xxxx</LoginName>
<Password>xxxx</Password>
<Company>xxx</Company>
</ns2:ApiAuthentication>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:GetCustomersRequest>
<ns1:CustomerID>123456</ns1:CustomerID>
<ns1:LoginName xsi:nil="true" />
<ns1:FirstName xsi:nil="true" />
<ns1:LastName xsi:nil="true" />
<ns1:Company xsi:nil="true" />
<ns1:Email xsi:nil="true" />
<ns1:Phone xsi:nil="true" />
<ns1:Phone2 xsi:nil="true" />
<ns1:MobilePhone xsi:nil="true" />
<ns1:Fax xsi:nil="true" />
<ns1:MainAddress1 xsi:nil="true" />
<ns1:MainAddress2 xsi:nil="true" />
<ns1:MainAddress3 xsi:nil="true" />
<ns1:MainCity xsi:nil="true" />
<ns1:MainState xsi:nil="true" />
<ns1:MainZip xsi:nil="true" />
<ns1:MainCountry xsi:nil="true" />
<ns1:TaxID xsi:nil="true" />
<ns1:EnrollerID xsi:nil="true" />
<ns1:SponsorID xsi:nil="true" />
<ns1:Field1 xsi:nil="true" />
<ns1:Field2 xsi:nil="true" />
<ns1:Field3 xsi:nil="true" />
<ns1:Field4 xsi:nil="true" />
<ns1:Field5 xsi:nil="true" />
<ns1:Field6 xsi:nil="true" />
<ns1:Field7 xsi:nil="true" />
<ns1:Field8 xsi:nil="true" />
<ns1:Field9 xsi:nil="true" />
<ns1:Field10 xsi:nil="true" />
<ns1:Field11 xsi:nil="true" />
<ns1:Field12 xsi:nil="true" />
<ns1:Field13 xsi:nil="true" />
<ns1:Field14 xsi:nil="true" />
<ns1:Field15 xsi:nil="true" />
<ns1:CreatedDateStart xsi:nil="true" />
<ns1:CreatedDateEnd xsi:nil="true" />
<ns1:GreaterThanCustomerID xsi:nil="true" />
<ns1:GreaterThanModifiedDate xsi:nil="true" />
<ns1:BatchSize xsi:nil="true" />
</ns1:GetCustomersRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
And here is the response:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Authentication header missing! Unable to Authenticate!</faultstring>
<detail />
</soap:Fault>
</soap:Body>
</soap:Envelope>
我的php代码:
$client = new SoapClient("http://mywebservice.asmx?wsdl",
array(
"trace" => 1,
"exceptions" => 0,
"cache_wsdl" => 0)
);
$namespace = 'http://mynamespace.com';
$creds = new stdClass();
$creds->LoginName = "xxxx";
$creds->Password = "xxxx";
$creds->Company = "xxxx";
$headers[] = new SoapHeader($namespace, 'ApiAuthentication', $creds, false);
$client->__setSoapHeaders($headers);
$response = $client->__soapCall("GetCustomers", array("CustomerID" => "123456"));
var_dump($response);
我已经多次查看我的代码并且找不到任何错误。我尝试了多种代码来设置凭据,设置soap客户端和soap标头等等。
每次都是相同的响应&#34;缺少身份验证标头!无法进行身份验证!&#34;
要检查的任何想法。我过去几年一直在做dot.net,我刚刚回到php。
提前致谢。
答案 0 :(得分:0)
使用Cookie而不是标头。如果您发现自己正在使用标题,请告诉我。
<强> PHP 强>
$client = new SoapClient('http://somesite/someservice.asmx?wsdl');
$client->__setCookie("LoginName", "myname");
$client->__setCookie("Password", "secret");
$client->__setCookie("Company", "999999999");
<强> ASP.NET 强>
string strLoginName = HttpContext.Current.Request.Cookies.Get("LoginName").Value;
string strPassword = HttpContext.Current.Request.Cookies.Get("Password").Value;
string strCompany = HttpContext.Current.Request.Cookies.Get("Company").Value;