0

I use this following code, to connect huawei hilink, but it always returns an error.

First I get the token and session via

http://192.168.8.1/api/webserver/SesTokInfo

Can you please help me fix the issue?

        string resulta = PostAndGetHTML("http://192.168.8.1/api/webserver/SesTokInfo");
        string tok = resulta.Substring(57, 32);
        string ses = resulta.Substring(108, 128);
        Postxml("http://192.168.8.1/api/user/login", tok, ses);

   public string PostAndGetHTML(string targetURL)
    {


        string html = string.Empty;
        string url = targetURL;

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.AutomaticDecompression = DecompressionMethods.GZip;

        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
        using (Stream stream = response.GetResponseStream())
        using (StreamReader reader = new StreamReader(stream))
        {
            html = reader.ReadToEnd();
        }
        return html; 
    }


   public  void Postxml(string destinationUrl, string token, string ses)
    {
        var client = new RestClient();
          string rawXml = @"<?xml version=""1.0"" encoding=""utf-8""?><request><Username>admin</Username><Password>" + Base64Encode("admin") + @"</Password></request>";
        client.BaseUrl = new Uri(destinationUrl);
        var request = new RestRequest(Method.POST);
        request.AddHeader("__RequestVerificationToken", token);
        request.AddCookie("cookie",ses);
        request.Timeout = 3000;
        request.ReadWriteTimeout = 3000;


        request.AddParameter("text/html", rawXml, ParameterType.RequestBody);
        IRestResponse response = client.Execute(request);

    }
ndmeiri
  • 4,979
  • 12
  • 37
  • 45

0 Answers0