开发者

Connecting to a web service with PHP given only username, password and certificate authority

I am successfully connecting, using Microsoft C#, to a Microsoft web service. I have to supply a username, password (in the C# code); and install a certificate (in .cer format) into the "Root Certificate Authorities" section of the system's certificates.

How can I connect to such a web service in PHP? The reason I ask is that all methods I have seen (such as wsdl2php, which creates a SoapClient subclass), seem to assume various things, such as SSL certificate, SSL key file and SSL key passphrase.

So it all confuses me. I'm not sure what should go where. I'm not sure where my "root c开发者_运维知识库ertificate authority" (the .cer file) should go, and where the username and password should go. Any ideas?


all can be done whith soapclient and stream_context_create using ssl options

<?php
$context = stream_context_create(array(
  'https' => array(
     'cafile' => '/path to file',
     'verify_peer' => true
  )));

new soapclient("https://localhost/index.php?wsdl",array(
  'login'=>'admin',
  'password'=>'passss',
  'stream_context'=> $context
));

it is not uncommon in soap to not use http auth but just an soap-call, the documnetation is essential

it can be rewarding to use soapclient whith classes using classmap to map soaptypes to php clases


Typically if you're calling a webservice using regular SSL your URL will look like:

https://username:password@myserver.com/mywebservice.php

Then there is the issue of the SSL certificate. I'm using something similar to read from an SSL protected SVN web front. I don't know of any other solution other than to log into the server as the user that is running your webserver (apache/IIS) and accepting the certificate manually. In the case of SVN you could make a checkout and it will ask you to accept the certificate. I'm not entirely sure how this would work for a plain HTTPS request but perhaps you can get the certificate by loading the webservice in a browser? (or using wget or something fancy if you're lucky enough to be running Linux)

Also, is your code the PHP code or the C# code? If it's C# you may need to do something else entirely.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜