I am using php soap to make calls to a web service but the operator of the service wants us to switch to non-wsdl mode so it doesn't need to be exposed. I get bad requests and looking at the request generated I notice one main difference between the requests going out.
<ns1:userpwd>password</ns1:userpwd>
vs.
<ns1:userpwd xsi:type="xsd:string">password</ns1:userpwd>
All the parameters have this additional xsi:type="xsd:string" Currently I am using
new SoapParam($password, "ns1:userPWD");
to generate the parameters. What do I need to do different to omit the xsi:type attribute from the xml for the call that eventually gets sent out?
Once again thinking the question through enough to write it up points to an answer:
new SoapVar("$password", XSD_ANYXML); produces the desired result in the request
Related
I have created some code to make calls to an external API (that I did not create). However, it has been described as 'Service-centric', while REST APIs are 'Resource-centric'.
What exactly needs changed to turn this into a service based call? I don't understand what the difference is. I understand I need to use HTTP verbs but I thought I was doing that already with cURL. Is this possible with cURL?
The API I have been passed contains a bunch of resource URLs as an example;
GET http://api.privateservice.com/Person?ID=123
POST http://api.privateservice.com/Person/SaveDetails/123
Think of resources as nouns, ie objects or records in your database. Think of actions as verbs, ie function calls.
The first example is indeed resource-centric. It's GETting a resource of type Person identified by 123.
The second example is not resource-centric because it's essentially a function call. REST and HTTP already establish conventions for saving a resource. In this case you simply need to PUT to the resource's URL, ie the same URL you retrieved with GET.
So upload the JSON (or whatever format) using:
PUT http://api.privateservice.com/Person?ID=123
If you are only passing in a few attributes, not the whole resource, there's another standard for that, PATCH:
PATCH http://api.privateservice.com/Person?ID=123
BTW It's a bit cleaner to use http://api.privateservice.com/people/123 as the URL.
I have a web application which I wrote in PHP. Each of my forms do an HTTP POST to a PHP file which processes the data and returns a result.
Now I want to use RAD Studio's Delphi XE4 to create an application which can be used on phones to perform basic functions on the site.
For example...
I have a function in my PHP file called F.
F Does some calculations with parameters passed using the $_REQUEST[''] directive.
So my question is: is there a way that I can use Delphi to post to my website and return the result.
I've searched for similar requests but no-one seems to have done this before.
I would even use a JavaScript file if someone can tell me how I can incorporate it?
I know jQuery has a $.ajax method, is there maybe a way to implement that?
I can assure you that you're not the first person to do an HTTP request via Delphi :)
You state that you're fetching the request data via $_REQUEST, so you'll get both POST and GET data, so perhaps these links might be of interest:
What's the simplest way to call Http GET url using Delphi?
What’s the simplest way to call Http POST url using Delphi?
I am working on building an REST API in PHP, I need to know if it's possible to to POST an array of methods/functions and params to my api script and have my code run the listed functions and print to the screen an array that the functions produced, example if a user sent a request to get a list of 5 photo url's it would post a PHP array with the 5 URLs in an array and then be able to use that array in the persons script who is using the API?
So basicly you post to a script with CURL a list, array of functions you want the API to run, the api returns an array of results but instead of formatting to JSON or XML it shows it on the screen as PHP array and then curl will let the user's code run the returned php array as real php in there script?
Sorry if this is confusing but it really seems that the bebo.com API works this exact way and possibly facebook API so I think this would work but could someone tell me? Possibly some examples of how to do it if it is possible, thanks
I have found that JSON-RPC is a fantastic solution for batching API requests. It is significantly simpler to put multiple API requests in a single JSON-RPC request than any XML solution I have seen (although only version 1.1 and higher of the spec supports this). Since it is all just JSON it works wonderfully regardless of what server-side (or client-side) language is consuming the results. The only problem I have found is that the spec is a little wonky if you want to implement all of the potential versions.
For safety, you should:
Strictly limit which PHP functions/methods anonymous users are allowed to call without authentication.
Use the PHP Reflection API to do initial validation of parameters. You can use reflection to do the following:
Ensure a method exists and is public (return an HTTP 404 if it does not, 403 if the user is not authorized).
Count the number of parameters a function or method accepts.
Determine parameters are optional or required.
Determine the names of parameters so they can be passed as a JSON object.
If you use PHP 5.1+ you can examine the doc comments to determine what the the accepted data type is for each parameter.
Strictly validate parameters further inside each API call.
I used to work with Lumen for REST, but turned out it was still too bloated for my goals, so I just went over this solution which I share with anyone may have interest.
https://github.com/joaoN1x/koolrest
I am using AMFPHP with great success to link my database with my Flex application. However I want to be able to test the remoting requests outside of flash, by typing something like:
http://localhost/amfphp/gateway.php?[WHAT DO I PUT HERE]
What do I put after the questionmark in order to have the browser (or a C++ http component) call the amfphp service, so that the http request needn't "initiate" from flash.
It sounds like you want to make an AMF call from PHP. You can't do this directly from a browser. The data would be returned in the binary AMF format, which of course PHP or a browser can't handle directly. I don't even think it can make the request.
You'll need a AMF client to make the call and decode the data - I suggest using SabreAMF.
Sabre AMF homepage
This is what simple client method call code looks like.
require 'SabreAMF/Client.php';
function make_request($param1,$param2){
$client = new SabreAMF_Client('http://your.server/amfphp/gateway.php');
return $client->sendRequest('your_amf_service.yourAMFmethod',array($param1, $param2));
}
you then invoke this like
$result=make_request('cow',300);
and it returns an array.
You'd probably want to set up a PHP class with all of your methods so you can call each one easily, of course.
AMFPHP has the service browser, which lets you simulate calls to your server-side service and see the responses. It basically does an internal CURL request back to the same service file and passes in the arguments you provided, and acts as if it was done directly from the client-side Flash app.
AMF being a binary format, things are probably not going to be that simple : you'll have to find out how your data is encoded...
As a first step, maybe you could, from your gateway.php script, just dump everything it receives to a file, when it's called from your flash component ?
This way, you could see how the received data looks like (and you'd know if it's passed in POST, or in GET).
Depending on what that data looks like, maybe you'll be able to "forge" a request to your server -- but I don't think it'll be as simple as just calling an URL from your browser...
Considering the AMFPHP gateway is just a mechanism to translate (from/to binary) and dispatch to a class/method with various incoming parameters and finally a return() of data - can you just unit-test directly against the method, thus skipping the entire AMF layer?
Is there a way to save the soap request SoapClient sends when calling __soapCall to a file instead of sending it to the actual server?
I'm trying to save the soap requests to a queue and then send them over a period of time (the requests will be very different).
I'm using Zend_Soap.
Take a look at Zend_Soap_Client_Local, especially the _doRequest() method and build your own class with your own logic.
If you want so see how they used Zend_Soap_Client_Local, take a look in tests/Zend/Soap/ClientTest.php, method testGetFunctions().