0

I can't manage to stablish a connection to Synology NAS from c# using RestSharp (or any other method)

    public void TryConnection()
    {
        var request = new RestRequest("/webapi/entry.cgi", Method.Post);
        request.AddParameter("path", "entry.cgi");
        request.AddParameter("api", "SYNO.API.Info");
        request.AddParameter("version", "1");
        request.AddParameter("method", "query");

        var client = new RestClient(new RestClientOptions("http://quickconnect.to/FDesign-GmbH:5000/") { FollowRedirects = true });

        var response = client.ExecuteGetAsync(request).Result;
        
        string s = response.ResponseUri.ToString();
    }

Result = "Request failed with status code Redirect".

from what i found i believe this is having something to do with redirects but i dont know how to handle it...

if i paste this Url manualy in browser i get feedback :

https://192-168-178-23.fdesign-gmbh.direct.quickconnect.to:5001/webapi/entry.cgi?api=SYNO.API.Info&version=1&method=query

same Url in Code:

    public void TryConnection()
    {
        var request = new RestRequest("/webapi/entry.cgi", Method.Post);
        //request.AddParameter("path", "entry.cgi");
        request.AddParameter("api", "SYNO.API.Info");
        request.AddParameter("version", "1");
        request.AddParameter("method", "query");
        request.AddParameter("query", "SYNO.API.Auth,SYNO.FileStation");

        var client = new RestClient(new RestClientOptions("https://192-168-178-23.fdesign-gmbh.direct.quickconnect.to:5001/") { FollowRedirects = false });

        var response = client.ExecuteGetAsync(request).Result;
        
        string s = response.ResponseUri.ToString();
    }

with code i get : "Error sending request"

Some help on this would be appreciated.

  • Check the full content of the returned message. I suspect this includes a redirect URL. – PMF Sep 16 '22 at 12:31
  • Yes, but that url in browser is wrong : "http://FDesign-GmbH:5000.quickconnect.to/webapi/entry.cgi?path=entry.cgi&api=SYNO.API.Info&version=1&method=query" – Bruno Frade Sep 16 '22 at 12:35
  • That would seem to be caused by a misconfiguration of the web api on the NAS side. But since it works with a normal browser, that is strange. – PMF Sep 16 '22 at 12:43
  • Have you tried using a GET-Request instead of a Post-Request here: var request = new RestRequest("/webapi/entry.cgi", Method.Get); //Instead of Method.Post When you open it directly in the browser its usally a GET-Request not a POST-Request – MarkusE Sep 16 '22 at 14:02
  • @MarkusE : Yes i have tried GET, same result. – Bruno Frade Sep 16 '22 at 15:17

0 Answers0