Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 联系一个网站,并在c中以字符串形式获取重定向url#_C#_Git_Version_Webrequest_Httpwebresponse - Fatal编程技术网

C# 联系一个网站,并在c中以字符串形式获取重定向url#

C# 联系一个网站,并在c中以字符串形式获取重定向url#,c#,git,version,webrequest,httpwebresponse,C#,Git,Version,Webrequest,Httpwebresponse,我注意到如果您访问git存储库的url,例如 您将自动被重定向到最新版本 在c#中是否有可能联系上述url,被重定向并将响应url作为字符串 这样,我只需执行string.Split(“/”)并获取最新的子字符串,即可快速轻松地检查应用程序的版本 致以最良好的祝愿 朱利安这就是我想到的(解决了): 欢迎来到堆栈溢出!堆栈溢出不是免费的代码编写服务,而是询问特定问题的地方。请开始编写代码,当您有关于该代码的特定问题时,请回来。一定要包括一个。另见。 static void Versionche

我注意到如果您访问git存储库的url,例如

您将自动被重定向到最新版本

在c#中是否有可能联系上述url,被重定向并将响应url作为字符串

这样,我只需执行string.Split(“/”)并获取最新的子字符串,即可快速轻松地检查应用程序的版本

致以最良好的祝愿


朱利安

这就是我想到的(解决了):


欢迎来到堆栈溢出!堆栈溢出不是免费的代码编写服务,而是询问特定问题的地方。请开始编写代码,当您有关于该代码的特定问题时,请回来。一定要包括一个。另见。
static void Versioncheck (double currentVersion)
    {
        //Get web response of git repository (/latest will forward you to the latest version)
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://github.com/[user]/[Project]/releases/latest");
        req.Method = "HEAD";
        req.AllowAutoRedirect = true;
        WebResponse response = (HttpWebResponse)req.GetResponse();
        //split the parts of the responseuri
        string responseUri = response.ResponseUri.ToString();
        string[] uriParts = responseUri.Split('/');
        //compare the latest part of the versionuri (version number) with the currect program version
        if (Convert.ToDouble(uriParts.Last(), CultureInfo.InvariantCulture) > currentVersion)
        {
            Console.WriteLine("Version " + uriParts.Last() + " is available! You can get the latest Version here:");
            Console.WriteLine("Project download page");
        }
        else
        {
            Console.WriteLine("Congrats! You are using the newest Version of programname!");
        }
    }