Laravel ServerException in RequestException.php when receiving simple JSON request -
i'm using laravel 5 framework communicate manufacturer, , i'm struggling in receiving callback:
here routes (set them both, test):
route::post('/callback', 'printcontroller@callback'); route::get('/callback', 'printcontroller@callback');
and simple method in controller:
public function callback(request $request) { var_dump( $request ); //storage::put('request.txt', $request); }
it works fine, if open site manually ( meaning, dump request , later create request file ) , when call like this:
/** * test callback option */ public function testcallback() { $callback_url = 'http://project.dev/callback'; // prepare response $response = array( 'time' => -microtime(true), ); $data = [ "id" => 907, "current_state" => "shipped", "merchant_sku" => "bst123", "ordered_on_date" => "2015-08-16t00:00:00+0200", "ship_by_date" => "2015-08-21t00:00:00+0200", "shipping_carrier" => "usps", "shipping_tracking" => "9499907123456123456781", ]; try { $result = guzzle::post($callback_url, [ 'verify' => false, 'headers' => [ 'content-type' => 'application/json', ], 'json' => $data, ]); $body = json_decode($result->getbody(), true); // fill response if ($body['success'] == true) { $response['success'] = true; $response['order_id'] = $body['work_order_id']; } else { $response['success'] = false; } } catch (exception $e) { // set error $response['success'] = false; $response['message'] = $e->getmessage(); } // save execution time $response['time'] += microtime(true); $response['time'] = round(abs($response['time']), 4); return $response; }
i error message:
serverexception in requestexception.php line 107: server error: `post http://project.dev/callback` resulted in `500 internal server error` response: <!doctype html> <html> <head> <meta name="robots" content="noindex,nofollow" /> <style> (truncated...)
edit: errorlike message in php_error.log
is:
[09-may-2016 12:24:20 utc] php deprecated: automatically populating $http_raw_post_data deprecated , removed in future version. avoid warning set 'always_populate_raw_post_data' '-1' in php.ini , use php://input stream instead. in unknown on line 0
any ideas i'm doing wrong and/or how debug , fix this?
by way: communication happens between 2 laravel frameworks in save machine, meaning, it's site.dev
sending request project.dev
.
edit: found in laravel error log when receiveing post. works find get.
[2016-05-09 15:21:25] local.error: exception 'illuminate\session\tokenmismatchexception' in d:\project.dev\vendor\laravel\framework\src\illuminate\foundation\http\middleware\verifycsrftoken.php:67
why laravel care this, since i'm sending request 'verify' => false
?
i solved it. moved routes outside middleware, doesn't require token validation:
route::post('/callback', 'printcontroller@callback'); route::get('/callback', 'printcontroller@callback'); route::group(['middleware' => ['web']], function () { ... }
just in case else has same problem: middleware not required here, since manufacturer doesn't use same session , can't provide token required.
Comments
Post a Comment