Friday, March 3, 2017

Send HTTP Post from VBA-Excel to Laravel

How do I catch an HTTP Post from VBA-Excel in a Laravel controller so that I can update a model? I am running my laravel application on Homestead. Below is a demonstration of what I've tried thus far with no success.

VBA-EXCEL

OSub httpPost()
Dim XMLHTTP As Object
Dim result As String
Dim argumentString As String
argumentString = "screen_name=ET"
Set XMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0")
XMLHTTP.Open "POST", _
    "http://exceltwitterbot.app:8000/request", False
XMLHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
XMLHTTP.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
XMLHTTP.send argumentString
MsgBox XMLHTTP.responsetext

Set XMLHTTP = Nothing
End Sub

Web.php

Route::post('/request', [
    'uses' => 'ExcelController@store',
    'as' => 'request.store',
]);

ExcelController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ExcelController extends Controller
{
    public function store(Request $request)
    {  
      $name = $request->only('screen_name);
      $excel = new Excelinput;
      $excel->screen_name = $name;
      $excel->save();
    }
}



via Colin Stadig

Advertisement