mardi 8 mai 2018

How to extract data from guzzle post request on server side - Laravel 5, Guzzle, Post Request, XML File Upload

I have the request as below from first server:

//Uploading file on current server

$file            = $request->file('file');
$destinationPath = storage_path('app/xml');
$fileName        = pathinfo($request->file('file')->getClientOriginalName(), PATHINFO_FILENAME);
$extension       = $file->getClientOriginalExtension();
$file->move($destinationPath, $fileName.'.'.$extension);

//Making a guzzle request

$chk_file = storage_path('app/xml/'.$fileName.'.'.$extension);

if (file_exists($chk_file)) {

    $client = new Client();
    $response = $client->request(
                'POST',
                $url,
                [
                    'multipart' =>
                    [
                        [
                            'name'     => 'FileContents',
                            'contents' => fopen(storage_path('app/xml/'.$fileName.'.'.$extension), 'r')
                        ],
                        [
                            'name'     => 'xml_header',
                            'contents' => 'some text',
                            'filename' => $fileName.'.'.$extension
                        ]
                    ]
                ]
            );
    echo $response->getBody()->getContents(); // I get here message from second server
}        

second server request

//this works,  
public static function index(Request $request)
    {
         return response()->json('some msg');
    }

//this does not work
public static function index(Request $request)
    {
         //How do I extract all the content sent by guzzle here?
         //I want something like: 
         $request->file('file');        //containing data  or 
         $request->get('xml_header');   //custom form data attached


         //uploading the file on second server
         ...
         return response()->json('some msg');
    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire