I am trying to write a small C#/.NET Core application which updates the RUT241.
Via Postman it worked flawlessly, but the multipart/form-data and file upload seems to be problematic. I get a 422 unprocessable-entity error.
Login and other API calls with Bearer key in the header work it is just the firmware which struggles me, can somebody provide an example script?
I already contacted Teltonika but got no response.
Update from RUT2M_R_00.07.11.2_WEBUI.bin to RUT2M_R_00.07.11.3_WEBUI.bin
Hi ms_kreisel,
I haven’t tested this on RUT241, but I use ssh
to update devices, something like:
#!/bin/bash
# Replace the following with the actual names/credentials
FW_NAME="<fw_name.bin>"
ROUTER_IP="<ROUTER_IP>"
ROUTER_PASS="<ROUTER_PASS>"
echo "Upgrade the FW"
sshpass -p "$ROUTER_PASS" ssh -o "ServerAliveInterval 2" root@$ROUTER_IP "sysupgrade -n /tmp/$FW_NAME"
echo "Upgrade started"
GOOD NEWS
A very detail loving colleague found the problem comparing byte after byte between the Postman and the .NET application traces with Wireshark (:
The problem seems to be on the consuming side in particular the parser and this behaviour is also a known problem:
When sending MultipartFormDataContent from HttpClient, the MediaTypeHeaderValue.TryParse does not handle multipart boundary value enclosed with quotes correctly · Issue #41237 · dotnet/aspnetcore
When using the .NET framework, the “MultipartFormDataContent” class, it automatically adds double quotation marks to the boundary in the HTTP header as suggested by the RFC 2046 section 5.1.1 to avoid parsing error (instead of creating them )
EXAMPLE:
Wireshark snippet of the two original HTTP headers, beside different strings .NET adds the quotation marks:
.NET version:
Content-Type: multipart/form-data; boundary="--------------------------056669261460634204916332"
Postman version:
Content-Type: multipart/form-data; boundary=--------------------------913503248038879267081972
We now manually remove the quotes and then it finally works but this is only a workaround and should not be necessary:
var boundary = form.Headers.ContentType.Parameters.First(o => o.Name == "boundary");
boundary.Value = boundary.Value.Replace("\"", String.Empty);
Maybe Teltonika should consider changing their parser to allow both variations especially because it is recommended by RFC 2046.
Same problem applies to RUT240 (firmwares).
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.