I have a PHP script that sends a SOAP request to an ASMX API that is owned by a dfferent division of the company that I work for. I developed this script in the WAMP environment on my personal company PC and it works fine in that environment, successfully recveiving and parsing the response. However when I upload this script to the LAMP-based development server (which was just setup) and attempt to run it through a web browser, I get a 500 Internal Server Error. The web engineer who setup the server says he installed and enabled the PHP SOAP extension. Does anybody know of anything else used in the code below that needs to be activated on the server that would cause a 500 error by its absence?
Here is the code that sends the request, minus the actual XML body, which is being processed correctly by the API. The code following this snippet simply pulls various values out of the arrays that are returned and echoes them out.
//Common SOAP client options that can be set.
$clientOptions = array(
'exceptions'=>true,
'trace'=>1,
'cache_wsdl'=>WSDL_CACHE_NONE,
'location' => $endpointURL);
//The creation of the client object. We pass it a reference to the WSDL.
$requestXML = '<GetRateQuote xmlns="<URL>">
CORRECTLY FORMATTED XML IS HERE
</GetRateQuote>';
$requestObj = new SoapVar($requestXML,XSD_ANYXML);
$client = new SoapClient($endpointURL . "?wsdl", $clientOptions);
//Retrieve the response.
$result = $client->GetRateQuote($requestObj);
//Put the data into a variable to be parsed
$data = $result->GetRateQuoteResult;....
Related
I'm trying to get my blog's RSS feed and manipulate it in PHP. Accord to the documentation, the XML feed for all Wordpress blogs can be downloaded at this address:
http://www.example.com/feed/atom/
I've written some simple code that works fine on a test server, but won't work on my hosted server:
$feedUrl = 'http://www.example.com/blog/feed/atom/';
$rawFeed = file_get_contents($feedUrl);
$feedXML = new SimpleXmlElement($rawFeed);
The reason for this is because my hosting provider prevents scripts making HTTP (port 80) connections back to the same server that they're running on.
How can I get access to the feed without needing to do a HTTP request to the same server?
I have tried accessing the URL directly (i.e. /home/example.com/blog/feed/atom), but nothing is found because it needs a proper request to generate the XML RSS feed. I've also tried a CURL request, but I got the same result.
It's a tricky problem! Thanks for any help!
Note: My solution needs to run on a non-WP page.
Some hosting providers might let you set up CRON jobs through their admin console, without having access to the command line. In a situation like that, you may be able to use a WP-CLI command to retrieve the output of the feeds, and save it to a file using something like "> filename.txt" at the end of the command.
See here: http://wp-cli.org/
And possibly here: http://wp-cli.org/commands/eval-file/
I am working on a php SoapClient. The Soap server is a .NET server.
Everything works fine when the client calls a http address and when the answer come from the server that the client calls.
The issue I have is that the client must call a https address and the server uses a load balancing system, leading to get an answer from another server (client calls serverX and get an answer sometimes from serverY, sometimes from serverZ, etc.).
Here is the php code that I use (works fine when no https and no load balancing, doesn't work with https and load balancing):
$client = new SoapClient('http://www.serverA.com/serviceB.svc?wsdl');
$immat = 'yadiyadiyada';
$params = array('immat' => $immat);
$result = $client->__soapCall('setImmat', array($params));
$id_found = $result->setImmatResult;
Any idea of what I should do? Any tips would be greatly appreciated!
Thanks
I at last found a work around.
Instead of instantiating the php SoapClient with the XML file provided by the server, I made a copy of it on the client side and I modified it a little bit. I only changed the "schemaLocation": server side, the value was something like "https://www.serverY.com/serviceB.svc?xsd=xsd0", I replaced it by "https://www.serverX.com/serviceB.svc?xsd=xsd0".
Now I instantiate the php SoapClient with this new file:
$client = new SoapClient('/local_path/wsdl.xml');
and it works!
$output = file_get_contents("http://www.canadapost.ca/cpc2/addrm/hh/current/indexa/caONu-e.asp");
var_dump($output);
HTTP 505 Status means the webserver does not support the HTTP version used by the client (in this case, your PHP program).
What version of PHP are you running, and what HTTP/Web package(s) are you using in your PHP program?
[edit...]
Some servers deliberately block some browsers -- your code may "look like" a browser that the server is configured to ignore. I would particularly check the user agent string that your code is passing along to the server.
Check in your PHP installation (php.ini file) if the allow_url_fopen is enabled.
If not, any calls to file_get_contents will fail.
It works fine for me.
That site could be blocking the server that you're using to access it.
When you run the URL from your browser, your own ISP is used to get the information and display in your browser. But when you run from PHP, the ISP of your web host is used to get the information, then it passes it back to you.
Maybe you can do this to check and see what kind of headers its returning for you?
$headers=get_headers("http://www.canadapost.ca/cpc2/addrm/hh/current/indexa/caONu-e.asp");
print_r($headers);
I've tried looking for a solution to this issue for a few days now and am getting quite confused.
Aim:
To have a PHP server ("Server A") communicate directly to another PHP
server ("Server B") when Server A is visited by user. It then sends a
query string to Server B to add in to Server B's database.
Full story:
A visitor will visit Server A and register to their website, as part
of their registration Server A will write to Server A's database with
all the visitors information. At this point I'd like Server A to load
a .php file on Server B and send a query string with it, for example:
http://example.com/api/add.php?name=Craig&age=21&key=32r932r9832yr813hr813rh1389ry13r7y31r.
Server B, having a PHP file requested from it, will take the variables
and run the script on add.php (take the variables and add it to it's
database).
Important note: I don't want the client machine to know this, initially I wanted to use JQUERY but realised this sends the request from the client machine and not the server directly.
What is the best way to do this?
Many thanks in advance!
Craig
Learn cURL. Here is an example to get you started:
<?php
$ch = curl_init('http://example.com/api/add.php?name=Craig&age=21&key=32r932r9832yr813hr813rh1389ry13r7y31r');
curl_setopt($ch, CURLOPT_HEADER, 0);
$response = curl_exec($ch);
curl_close($ch);
?>
I've seen blocks of code like this
use Win32::OLE;
my $Notes = Win32::OLE->new('Notes.NotesSession')
or die "Cannot start Lotus Notes Session object.\n";
my $database = $Notes->GetDatabase("",'mail\VIMM.nsf');
but my script is running on a virtual webfusion apache service so how do you establish a connection to database on my domino server, I have control of its acl and its a website so can pass in a username & password. The script & 'POST' data is sent by a third party gateway with results of the transaction (Success/ Fail + name value pairs etc) which I need to capture. I can't do it directly on the domino server because although Domino supports PERL scripts, they will only work if PERL is also installed on the server which isn't an option.
Lotus Domino is also a web application server so you can communicate with the server using HTTP (GET and POST) from your perl script on the Apache server.
This might require changes to the Domino application in question in order for it to serve the content you expect.
Also, you can provide a WebService on your Domino Server.
For OLE/COM to work, Perl and the script have to be located on a server where Notes and/or Domino are installed. Otherwise, the OLE/COM classes are not installed and not available.
As Per and Klaus mentioned, if you can't put Notes/Domino on the machine with Perl on it, you have to switch to some sort of webbased communication.
If you are not limited to COM/OLE, you could use the IBM Lotus Domino Data Service, which is new in Domino Designer 8.5.3 Upgrade Pack 1:
The IBM® Lotus® Domino® Data Service is a REST API that accesses
databases on Domino servers. It is part of Domino Access Services.
The Domino Data Service receives requests and sends responses using
HTTP and HTTPS protocols with body content in JSON format.
The Domino Data Service allows you to obtain information on databases,
views, folders, and documents. You can update, add, and delete
documents.
The underlying problem is that a url such as http://www.mysite.com/thankyou?orderno=123 won't work in a Lotus Domino website because the ? is a special character (eg ?openagent, ?opendatabase) to the Domino web engine. You also can't use http://www.mysite.com/(thankyou)?openagent?orderno=456 (I tried), in both cases all you get is 404 page not found error and a domino log error "don't understand the url". The question was originally asking for help with Perl to solve the problem but I couldn't Perl scripts to run on my webfusion community server but fortunately quickly had success with this simple php script:
<?php
$params = "";
$url = "http://www.mywebsite.co.uk/";
$path = "wpx/website.nsf/httpagent?openagent";
if($_GET) {
$kv = array();
foreach ($_GET as $key => $value) {
$kv[] = "$key=$value";
}
$params = join("&", $kv);
}
print "<script>window.location.href=\"" . $url . $path . "&" . $params . "\"</script>";
?>
The script is placed on my webfusion server under a subdomain which effectively translates the url into a format that Domino can handle, the format ?openagent&orderno=456 is easily handled by either a java or Lotusscript agent, the parameter is extracted from the CGI Request_Content field.
The redirect means I don't for now need to manipulate data in the domino database directly, it also means that with the exception of the url translation script all the website code is in the domino database.