从C#控制台应用程序调用带有基本身份验证的php NuSoap webservice

时间:2016-10-25 09:15:01

标签: c# php web-services authorization nusoap

问题是凭据没有被传递,这里是我的代码

caseTracking.wsCaseTracking  ct = new caseTracking.wsCaseTracking();
ct.UseDefaultCredentials = false;
NetworkCredential netCredential = new NetworkCredential("test", "*********");
Uri uri = new Uri("http://exampleURL.com");
ICredentials credentials = netCredential.GetCredential(uri, "Basic");

ct.Credentials = credentials;
ct.PreAuthenticate = true;
string exists = ct.wsCaseExists("12345678", "12345");

Fiddler 2 Auth标签说

没有代理授权标头。

没有授权标题。

这只适用于SoapUI if 先发制人的认证:先发制人的认证是打勾的

php auth是:

function doAuthenticate(){
$authorized = false;
if(isset($_SERVER['HTTP_AUTHORIZATION']) && strlen($_SERVER
['HTTP_AUTHORIZATION']) > 0 && !isset($_SERVER['PHP_AUTH_USER']) && !isset
($_SERVER['PHP_AUTH_PW']))  {
list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':' ,   
base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
if( strlen($_SERVER['PHP_AUTH_USER']) == 0 || strlen($_SERVER
['PHP_AUTH_PW']) == 0 ) {
unset($_SERVER['PHP_AUTH_USER']);
unset($_SERVER['PHP_AUTH_PW']);
}
}

if(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW']) ) {
if($_SERVER['PHP_AUTH_USER'] == config_item('soap_username') && $_SERVER  
['PHP_AUTH_PW'] == config_item('soap_password') ) $authorized = true;
}
return $authorized;
}

任何帮助都将非常感谢,提前感谢

0 个答案:

没有答案