[英]C# NetworkCredential in PHP
I am trying to access a webservice through PHP. 我正在尝试通过PHP访问Web服务。 The webservice returns a byte array with a jpeg image, which is then shown on a webpage.
Web服务返回带有jpeg图像的字节数组,然后将其显示在网页上。
Today the service is accesses by a C# call, like so 今天,可以通过C#调用访问服务,就像这样
ImgService i = new ImgService();
The credentials are set like this: 凭据设置如下:
i.Credentials = new System.Net.NetworkCredential(username, password, domain);
Access to webservice: 访问网络服务:
byte[] result = null;
result = i.GetThumbNail(raceId, startNum, seasonId, height, width, true);
Response.ContentType = "image/jpeg";
Response.BinaryWrite(result);
The service is working fine in C# but now I need to access it through PHP and the only image I am getting is "missing.jpg". 该服务在C#中运行良好,但是现在我需要通过PHP访问它,而我得到的唯一图像是“ missing.jpg”。 I am not sure if this means that the credentials are wrong or if something else is wrong, but I feel very unsure about the credentials part.
我不确定这是否意味着凭证错误或其他错误,但是我对凭证部分不确定。
This is the PHP code without any credentials: 这是没有任何凭据的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).'">';
I have also tried using calls like this: 我也尝试过使用这样的调用:
$headers = array(
'username' => 'user',
'password' => 'pass',
'domain' => 'domain'
);
$header = new SoapHeader("http://tempuri.org/", 'UserCredentials', $headers, false);
$client->__setSoapHeaders($header);
$result = $client->GetThumbNail(parameters);
Both versions gives me the same missing.jpg and no error message. 两种版本都给我相同的missing.jpg,并且没有错误消息。 I feel I would get an error if the service did not accept the call?
如果服务不接受呼叫,我会收到错误消息?
Did not manage to solve this problem with the old web service, so I ended up creating a new HttpHandler doing the same thing the old service did. 用旧的Web服务无法解决这个问题,因此我最终创建了一个新的HttpHandler来完成与旧服务相同的操作。 Oh well...
那好吧...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.