PHP 中的 C# NetworkCredential

C# NetworkCredential in PHP

我正在尝试通过 PHP 访问网络服务。 Web 服务 returns 带有 jpeg 图像的字节数组,然后显示在网页上。

今天服务是通过 C# 调用访问的,就像这样

ImgService i = new ImgService();

凭据设置如下:

i.Credentials = new System.Net.NetworkCredential(username, password, domain);

访问网络服务:

byte[] result = null;

result = i.GetThumbNail(raceId, startNum, seasonId, height, width, true);
Response.ContentType = "image/jpeg";
Response.BinaryWrite(result);

该服务在 C# 中运行良好,但现在我需要通过 PHP 访问它,而我得到的唯一图像是 "missing.jpg"。我不确定这是否意味着凭据错误或其他错误,但我对凭据部分感到非常不确定。

这是没有任何凭据的 PHP 代码:

$client = new SoapClient("http://www.example.com/imgService.asmx?WSDL");
$result = $client->GetThumbNail($args['race'], $args['startnumber'], $args['year'], 0, 0, true);
$image_data = $result->GetThumbNailResult;
echo '<img src="data:image/jpeg;base64,'.base64_encode($image_data).'">';

我也试过这样调用:

$headers = array(
                            'username'  =>  'user',
                            'password'  =>  'pass',
                            'domain'    =>  'domain'
                            );
$header = new SoapHeader("http://tempuri.org/", 'UserCredentials', $headers, false);
$client->__setSoapHeaders($header);
$result = $client->GetThumbNail(parameters);

两个版本都给我相同的 missing.jpg 并且没有错误消息。我觉得如果服务不接受调用我会得到一个错误?

旧的 Web 服务无法解决这个问题,所以我最终创建了一个新的 HttpHandler 来做与旧服务相同的事情。 好吧...