PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, February 25, 2022

[FIXED] How to make test POST request in php artisan?

 February 25, 2022     laravel, laravel-5.2     No comments   

Issue

I need to make POST request, can I do it via PHP artisan?

I tried this using GuzzleHttp, but I get error:

ServerException in RequestException.php line 107:
Server error: `POST http://localhost/public/api/order` resulted in a `500 Internal Server Error` response:
<!DOCTYPE html>
<html>
<head>
<meta name="robots" content="noindex,nofollow" />
<style>
(truncated...)

So, is it possible with artisan?


Solution

Not sure how efficient my method is, but this is an example I have run in the past.

  • Go into project directory.

  • Type php artisan tinker

  • Create an array of paramaters to pass:

$params = ['paramOne' => 'valueOne', 'paramTwo' => 'valueTwo'];

  • Create a new instance of the request you want to send. The default request type will be:

$request = Illuminate\Http\Request::create($uri, $method, $params);

  • If you created your own request class from the Illuminate one, A custom request could be something like this:

$request = App\Http\Requests\MyExtendedRequest::create($uri, $methodType, $params);

$uri is where you want to send the request $methodType is the type of HTTP Method to use (GET, POST, PUT, etc)

  • Create controller that handles the request

$controller = new App\Http\Controllers\MyController;

  • Submit the request.

$response = $controller->storeMission($request);



Answered By - Andrew Nolan
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing