Get the data posted to URL in laravel - guzzle

I'm using an API, for which i'm passing callback url. To this callback url data will be posted from api.
How can I get this data from callback url.
This is my code.
In response data is not there.
public function getData(Request $request){
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'api?callbackurl=url/getData'
]
]);
}

You callback URL is just another Laravel action. Create an action for url/getData (but you probably should to full URL instead) and wait for the data there.

Related

Retrieve file POST to Laravel 5

I'm trying to post a file to my upload function in Laravel. To keep things simple I'm using Postman to test it. According to the documentation, the way to access a file Request is:
$request->file('image')
so my controller function begins with :
if ($request->file('image')->isValid()) {
$file = $request->file('image');
}
And my post request:
As you can see the parameter is NULL.
So what is the correct way to access a file post request in the controller?
Thanks.
$image = $request->hasFile('image');
if(isset($image)){
//perform operation
}
The above should be what you need to check if there is a file in the request and then preform operations you want on the file.

Extract SOAP Specific Values And Return in PHP

Im new to SOAP UI, so is there any method to extract specific values from SOAP UI and return in PHP i want to extract data from this Courier Service Tracking SOAP API and show it in PHP
SOAP API : http://webapp.tcscourier.com/codapi/Service1.asmx
SOAP Request : http://webapp.tcscourier.com/codapi/Service1.asmx?op=GetCNDetailsByReferenceNumber
Any help would be much appreciated.
Thanks in advance.
I think what you might want to do is:
First you init a connection to the remote soap-Server, therefore you need to initiate a client
$client = new SoapClient('http://webapp.tcscourier.com/codapi/Service1.asmx?WSDL');
Since its a public API you don't need Login Credentials
Then you want to call the remote Method, e.g. getAllCities and store the response in a variable;
$response = $client->getAllCities();
Now you can view the result:
var_dump($response);
To be sure nothing wents wrong you can put the code above in try...error
$client = new SoapClient('http://webapp.tcscourier.com/codapi/Service1.asmx?WSDL');
try {
$response = $client->getAllCities();
} catch (SoapFault $e) {
var_dump($e);
}
HTH - best regards,
Lupo

ZF2 how to populate a form that failed a POST request into a GET redirect

I'm following REST standard where you use a POST action to create a resource and GET to show data.
That includes using GET to show a creation form and POST to handle the actual creation of the resource (AKA, saving to database).
In the case the POST request fails (lets say, a duplicate email address), a 302 is returned as a response, redirecting the user back to the form (kind of as a GET /resource/create with 302).
How do I persist the data sent from POST after the redirection in ZF2?
Or, maybe ZF2 doesn't support this/we're not supposed to do a 302 redirection?
I just think you want to pass data back to form. And display data on each fields. Usually, for failed request you don't need make redirection. Just display the form and data. Just use redirect when the process success (saving to database).
$form = new Form(); // your form
$request = $this->getRequest();
if ($request->isPost()) {
$form->setData($request->getPost());
if ($form->isValid()) {
// saving data here then redirect
$this->redirect()->toRoute('route', array('action' => 'name'), array('param => 1'));
}
}
return array('form' => $form);

CakePHP: Distinguish between regular http and REST calls

I want the same Controller routines to serve both regular web-based page loads as well as REST calls. I have REST handling set-up in my routes.php:
// Setup REST Handling
Router::mapResources( '<ControllerName>' );
Router::parseExtensions();
Let's take for example, the add() method - how do I distinguish inside this method how the call is being made?
To elaborate on the issue:
public function add() {
$status = array();
if( $this->request->is( 'post' ) ) {
// Read POST body
$entityBody = file_get_contents( 'php://input' );
}
}
As you can see in the above code, I'm detecting POST requests and will deal with the request accordingly. What I need to figure is whether the post data is coming from a REST call of from a web-form. If the data comes from a web-form, it'll be in the request->data array whereas for a REST call, it'll be in XML form.
I'll deal with the data accordingly and dish out an appropriate response.
Thanks.
Use the CakeRequest object, see the documentation, works the same as with post.
$this->request->is('put');
is('get') Check to see if the current request is a GET.
is('put') Check to see if the current request is a PUT.
is('post') Check to see if the current request is a POST.
is('delete') Check to see if the current request is a DELETE.

Can someone help me with POST method in Slim Framework?

I can set a GET method in Slim to get data from my database but my problem is the POST method, i don't know how to use it correctly. I do some code like:
$app->post('/login',function() use ($app){
$inputs = json_decode($app->request()->getBody());
$result = json_encode($inputs);
return $result;
});
I wanna make a login function by POST method but this is just an example I want to show the data that have been sent in the body by json. I used Advanced Rest Client to test but the result is always "null".
I'm new to Rest and Slim Framework too. Thanks for any helpful idea !
using return doesn't do anything in terms of viewing the output within that route callback function. use print, print_r, echo, $app->response->setBody('Foo'), or $app->response->write('Foo')
in terms of the post, did you try using $data = $app->request()->post() to get your data?