I hosted an empty page called api.php on a website
What I would like is to write a php or javascript script that will echo everything received from a callback function and display it without specifying the parameter of what the callback is sending ( as they may vary )
example :
var message = MessageResource.Create(
to: new PhoneNumber(toNumber),
from: new PhoneNumber(fromNumber),
body: msgBody,
provideFeedback: true,
statusCallback: new Uri("https://mywebsite/api.php"));// <--- the call back method will make a get or post request to the website I hosted
Now what should I write in the api.php ?
I tried to read the documentation on the rest api but the problem is ... I don't know what or how many parameter the statusCallback will send, so I want something like : no matter what http-request is coming , display the data in a human-friendly way.
Note : I'm aware of the previously answered question on Http Test server that accept GET/POST where sites like http://requestb.in/ and http://httpbin.org/, do the 90% job I'm trying to do , but I'm trying to do the same thing they are doing but using my own personal link so I can control the data the way I want
(the data being sent have 16k lines , and I want to chose when to erase them or do whatever)
-
Related
I'm trying to integrate a virtual paying system from a bank into my website.
The bank system makes an asynchronous HTTP call to a URL that I define (a PHP document), and from there I try to get the order ID and mark the order as paid.
The problem I'm facing, is that with only the HTTP call I don't seem to be able to get this ID parameter, as the expected result (the couchdb documnt is marked as payed) is not there.
But, when I browse to my document and I paste after it the content of the HTTP call, then it works, like so:
http://example.com/crud.php?Ds_SignatureVersion=xxx&Ds_MerchantParameters=xxx&Ds_Signature=xxx
On my crud.php I do the following:
$test = $_GET['Ds_MerchantParameters'];
Why am I managing to get this parameter when I browse to the URL, but not when the bank system makes the HTTP POST call?
If the bank system issues a POST request to your site, the passed parameters are not in $_GET, but in $_POST. So change
$test = $_GET['Ds_MerchantParameters'];
to
$test = $_POST['Ds_MerchantParameters'];
If you want to be able to use both GET and POST requests for the page, you can also use $_REQUEST:
$test = $_REQUEST['Ds_MerchantParameters'];
My goal is to create a group locker for every person in the class and upload a file to that locker. So first I'm calling
POST /d2l/api/lp/(version)/(orgUnitId)/groupcategories/
in order to create a category. That also creates a group for every user and automatically enrolls them. I then create a locker for each group in the category by calling
POST /d2l/api/lp/(version)/(orgUnitId)/groupcategories/(groupCategoryId)/locker
That works perfectly and at this point every student has it's own group with a locker assigned to the group. It is then up to the file uploading part.
Using the
POST /d2l/api/le/(version)/(orgUnitId)/locker/group/(groupId)/(path)
call I am trying to send a file, but all I get is a 404 error with no response provided. According to D2L's website, 404 would indicate that the group doesn't exists, which is not true since the groupId is received from the first call and works for the second one. For the header I use the array:
$h = array(
'Content-Type: multipart/form-data',
);
The contents are:
$contents = array("FileDescription" => json_encode(
array("Description" => "YY",
"IsPublic" => true
)),
"FILEFILE");
The POST is performed using cURL (php) and the code is mostly the code provided on D2L's website (a modified version of doValenceRequest function). I've tried multiple different headers, as well as different formats for the contents array. No matter what I do, the 404 error is being returned. I've even tried to just create a simple folder instead of uploading a file, but got the same issue. Am I doing something wrong?
Locker file uploads use the simple upload (not resumable) pattern, but, because you send a JSON document along with the file data, you have to use the RFC2388 multipart/mixed pattern, with a POST. See simple upload section on multi-part mixed patterns to see what those HTTP packets looks like.
Of particular note: the HTTP content-type is multipart/mixed and not multipart/form. Also, please be certain that you're actually sending a POST, not a PUT. Some HTTP libraries are pretty finicky around the use of multipart\mixed payloads, and you may find yourself having to hand-cook the entire HTTP request body to get the parts correctly formatted, and tune the headers a bit, before you send the request.
Note also that you should always be sending the JSON document part first in the list of parts, just as in the pattern examples in the documentation.
I am using plivo and have calls answered by welcome.php as my welcome url.
When a call is answered, I pass it to conf_handler.php and enter it into a conference:
$conf_attr = array(
'callbackUrl' => $host.'conf_handler.php',
'callbackMethod' => "POST",
);
$r->addConference($conf_name,$conf_attr);
echo($r->toXML());
How can I store both the callUUID and call_duration (once hang up) as a variables within conf_handler.php? Are they posted to the page with the callbackMethod? Or do I need to somehow use GET to look them up (how would I do this?) http://plivo.com/docs/api/call/#call_detail
you can do both ways.
1) From hangup_url (within your welcome.php). When a call is answered, Plivo sends a POST request with a set of parameters including the two. So you can parse the request from there. (Check out the "Request Parameters" section at http://plivo.com/docs/xml/request/)
2) From callbackUrl (within your conf_handler.php'). Once you set up theconf_handler.phpin thecallbackUrl`, Plivo will send a set of parameters as described at http://plivo.com/docs/xml/dial/#dialcallbackUrl
After that, you just need to parse the POST request and store as variables. (perhaps you could refer to http://www.tutorialspoint.com/php/php_get_post.htm)
Let me know if anything isn't clear. And I work at Plivo.
I have data in string format in a single variable in a php file on a wordpress site.
I want to fetch that variable's value through a php file on different server.
I want a way which will send that variable to my receiving php file that I have created on different server and print that values here.
In short, e.g. let there is data in mydomain1.com/send.php
which need to be stored or displayed in mydomain2.com/receive.php
But, without using form.There is no html form in sending file and also I don't want it since no redirection should be done.Just on a function execution in sending file data need to be transferred and displayed only on receiving end.
(I tried to find out solution for this using cURL.But, everywhere I found code to send data but what about receiving data, how can I capture that sent data and display at receiving end.)
If there is another solution except cURL or form submission I would appreciate.
Please help soon.
there are a lot of ways to do this, one way would be a SOAP client/server solution..:
you have basically 2 php files, one file on server1 is let say the client.php and on the other server there is the file named server.php which will receive all the data sent from client.php on server 1... here is a simple source, you need to change the URLs in the script to your server/client URLs so it works..:
client.php
<?php
//This is the SOAP Client which will call a method on Server 2 with passing some data:
//uri is the location where client.php is located, and "location" is the exact location to the client, including the name "client.php"
$client=new SoapClient(NULL,array("uri"=>"http://localhost/test","location"=>"http://localhost/test/test.php"));
$message=$client->hello("Hello World");
echo($message);
?>
server.php
<?php
//This is the SOAP Server
class server2{
public function hello($data){
return "I received following data: " . $data;
}
}
//the URI here is the location where the server.php is located.
$settings = array("uri"=>"http://localhost/test/");
$s=new SoapServer(null,$settings);
$s->setClass("server2");
$s->handle();
?>
Here's a tutorial: http://davidwalsh.name/execute-http-post-php-curl
Basically you can send the urlencoded values using CURLOPT_POSTFIELDS
I'm trying to replace RSS polling with PubSubHubbub on my site. I'm able to use the subscriber library that google offers to send the subscription request. From the code it looks like it sends a post request via cURL with the RSS URL and a callback URL.
So this is where I need some direction:
In order to complete the subscription request my callback URL has to receive a GET request and then echo back a value from the GET request along with a 200 response. How do I get the parameters from the GET request? Is the echo done again via cURL? If so what option should include the 200 response?
This very simple script should be a start:
echo $_GET["request_name"];
this will output the GET parameter request_name and (implicitly) send a 200.
It's also a good idea to explicitly declare a content type before echoing, to prevent the default content type (usually "text/html") from kicking in:
header("Content-type: text/plain");
Note that when echoing external data, you may need to sanitize the output first - if the for example the output format is HTML, you would want to do something like echo htmlspecialchars($_GET["request_name"]); to prevent Cross-Site Scripting.
There was recently a thread on the php-dev mailing list about this. The reason you can't access 'hub.challenge' in the $_GET superglobal is due to register_globals. Basically PHP cleans up any argument names before creating the superglobals. Any dots will be converted to underscores. It's looking to be 'fixed' in PHP 6, but not before due to BC issues.
Here's the thread about it.