• 怎么用程序获取远程url执行后的图片地址


    远程URL:https://121.199.16.229:8890/generate.cgi?rbid=1001&esn=22021434025005&pic=png&count=1&pix=250&cor=lo&comm=%E6%B5%A6%E6%B1%9F%E6%B8%B8%E8%A7%881%E5%8F%B7%E9%BE%99%E8%88%B9%2F%E5%B7%A5%E8%A1%8C%E5%8F%B7%EF%BC%8C2013%E5%B9%B46%E6%9C%881%E5%8F%B7%EF%BD%9E2013%E5%B9%B46%E6%9C%8831%E5%8F%B7%EF%BC%8C14%3A00
    执行后:会生成一个图片地址 如https://121.199.16.229:8890/cgi/1001313097265699.png

    怎么用程序 通过 内部访问 远程URL 获得这个 图片的URL

    回答:

    HttpWebRequest设置AutoRedirection就可以了。它会自动处理301跳转。

    添加System.Net和System.Security两个dll,引入相应命名空间。

            static void Main(string[] args)
            {
                HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("https://121.199.16.229:8890/generate.cgi?rbid=1001&esn=22021434025005&pic=png&count=1&pix=250&cor=lo&comm=%E6%B5%A6%E6%B1%9F%E6%B8%B8%E8%A7%881%E5%8F%B7%E9%BE%99%E8%88%B9%2F%E5%B7%A5%E8%A1%8C%E5%8F%B7%EF%BC%8C2013%E5%B9%B46%E6%9C%881%E5%8F%B7%EF%BD%9E2013%E5%B9%B46%E6%9C%8831%E5%8F%B7%EF%BC%8C14%3A00");
                ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);//验证服务器证书回调自动验证
                WebResponse webResponse = webRequest.GetResponse();
     
                Console.WriteLine(webResponse.ResponseUri.AbsoluteUri);//输出https://121.199.16.229:8890/cgi/1001363993292848.png
            }
     
            public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
            {   // 总是接受    
                return true;
            }
  • 相关阅读:
    118. Pascal's Triangle
    697. Degree of an Array
    1013. Partition Array Into Three Parts With Equal Sum
    167. Two Sum II
    ol7 禁用mysql 自启动
    pgsql常用命令
    清空history 命令记录
    pgsql启动报错
    在rhel 7.4中安装glibc-devel-2.17-196.el7.i686包的过程详录
    postgresql-9.2 install
  • 原文地址:https://www.cnblogs.com/guwei4037/p/5592352.html
Copyright © 2020-2023  润新知