SMS Gateway for Android produces HTTP 500 Error

Luciano Lingnau 4 years ago

I'm trying to use the Traccar SMS Gateway for Android (https://github.com/traccar/traccar-sms-gateway) and interact with it using powershell. However, I seem to get a 500 response when I try to send an SMS. Any suggestion or where I can look up what might be causing the 500 code?

If I mess up the token the error changes to 401, so at least the authentication part must be working (it's my assumption). Here's the code:

$params = @{"to"="+4915229591111";"message"="Test";}
$header = @{"Authorization" = "ede92604"}
Invoke-WebRequest -Uri "http://192.168.26.141:8082/" -Method POST -Body $params -Headers $header

Unfortunately I get:

Invoke-WebRequest -Uri "http://192.168.26.141:8082/" -Method POST -Body $params -Headers $header
Invoke-WebRequest : The remote server returned an error: (500) Internal Server Error.
At line:5 char:1
+ Invoke-WebRequest -Uri "http://192.168.26.141:8082/" -Method POST -Bo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Ideas and suggestions welcome. :)

Anton Tananaev 4 years ago

It doesn't seem like you're sending in the right format. You need to send JSON data.

Luciano Lingnau 4 years ago

It doesn't seem like you're sending in the right format. You need to send JSON data.

Oh, thanks for the hint and you're absolutely right. With a very small change to the code it starts working. Pretty nice. This is the "working" code if anyone's interested:

$params = @{"to"="+4915229591111";"message"="Test";}
$header = @{"Authorization" = "ede92604"}
Invoke-WebRequest -Uri "http://192.168.26.141:8082/" -Method POST -Body ($params|ConvertTo-Json) -Headers $header