I am trying to create a desktop app using c# that will manipulate my Laravel website's database(MySQL). So I am creating API routes to act as a middleman. I actually solved my issue by changing the code but did not understand why it was not working earlier. I am new to both Laravel & c# and coding some stuff just to learn some things.
This is my c# code to send a post request
WebClient client = new WebClient();
string postUrl = "http://mywebsite.com/api/v1/handshake";
var reqparm = new System.Collections.Specialized.NameValueCollection();
reqparm.Add("param1", "<any> kinds & of = ? strings");
reqparm.Add("param2", "testing parameter two");
byte[] response= client.UploadValues(postUrl, reqparm);
string result = System.Text.Encoding.UTF8.GetString(response);
MessageBox.Show(result);
This is my route in Laravel (Outside of middleware)
Route::prefix('v1')->group(function(){
Route::post('handshake','Api\SomeController@handshake');
});
The problem that I'm curious about is when my controller was like this :
public function handshake(Request $request)
{
return json_encode($request);
}
Respone was : {"attributes":{},"request":{},"query":{},"server":{},"files":{},"cookies":{},"headers":{}}
When I change the handshake method to this :
public function handshake(Request $request)
{
return json_encode($request->param2);
}
The response was: "testing parameter two"
So I wonder why the response was empty when I returned json_encode($response).
Is Illuminate Request a different type of object that causes this, or is it something else I am missing? It will be very helpful if you explain the reason why it's not worked