简体   繁体   English

PHP中的C#NetworkCredential

[英]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.

相关问题 C#替换来自NetworkCredential的邮件 - C# replace the mail from NetworkCredential 获取当前用户的 NetworkCredential (C#) - Getting NetworkCredential for current user (C#) C#System.Net.NetworkCredential - c# System.Net.NetworkCredential C#中的NetworkCredential在分配给HttpRequest对象时如何工作? - How does NetworkCredential in C# works when assigned to a HttpRequest object? c# NetworkCredential 和 System.Net.WebRequest 存储在代码中加密 - c# NetworkCredential and System.Net.WebRequest store crypted in code C#ASP .NET; 获取登录用户的NetworkCredential对象? - C# ASP .NET; Get the NetworkCredential Object for the logged in user? 为什么使用“新的NetworkCredential(用户名,密码)”不适用于我的网站的基本身份验证(来自WinForms C#应用程序)? - why is use of “new NetworkCredential(username, password)” not working for Basic Authentication to my website (from a WinForms C# app)? 在c#的“ System.Net.NetworkCredential”中使用未过载的webclient输入网页身份验证 - enter webpage authentication with webclient that's not overloaded in “System.Net.NetworkCredential” in c# Blazor 中的网络凭据 - NetworkCredential in Blazor 模仿和NetworkCredential - Impersonation and NetworkCredential
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM