首页 > 其他分享 >webclient download file The remote server returned an error: (403) Forbidden,

webclient download file The remote server returned an error: (403) Forbidden,

时间:2023-07-05 12:56:11浏览次数:26  
标签:remote returned Forbidden request System UserAgent WebRequest HttpWebRequest usi

class WebpWebClient:WebClient
    {
        protected override WebRequest GetWebRequest(Uri address)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);
            //req.UserAgent = "[any words that is more than 5 characters]";
            request.UserAgent = "testrequest";  
            return request;
        }
    }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Net.Http;
using System.Drawing;
using System.Net;
using System.IO;
using ImageProcessor.Imaging.Formats;
using ImageProcessor;
using System.Diagnostics;
using System.Security.Policy;

namespace ConsoleApp7
{
    class WebpWebClient:WebClient
    {
        protected override WebRequest GetWebRequest(Uri address)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);
            //req.UserAgent = "[any words that is more than 5 characters]";
            request.UserAgent = "testrequest";  
            return request;
        }
    }
    internal class Program
    {
        static void Main(string[] args)
        {
            WebClient_Download_File();
            Console.ReadLine();
        }

        static void WebClient_Download_File(string url = "https://upload.wikimedia.org/wikipedia/commons/a/a1/Johnrogershousemay2020.webp")
        {
            for(int i=0;i<10;i++)
            {
                string downloadedWebpFile = $"{DateTime.Now.ToString("yyyyMMddHHMMssffff")}{Guid.NewGuid().ToString()}.webp";
                WebpWebClient client = new WebpWebClient();
                client.DownloadFile(url, downloadedWebpFile);
                Console.WriteLine($"{DateTime.Now.ToString("yyyyMMddHHMMssffff")} {downloadedWebpFile} in {System.Reflection.MethodBase.GetCurrentMethod().Name}");
            } 
        }
   }
}

 

Referenced from https://stackoverflow.com/questions/16735042/the-remote-server-returned-an-error-403-forbidden

标签:remote,returned,Forbidden,request,System,UserAgent,WebRequest,HttpWebRequest,usi
From: https://www.cnblogs.com/Fred1987/p/17528240.html

相关文章

  • org.apache.spark.shuffle.FetchFailedException: The relative remote executor(Id:
    问题描述org.apache.spark.shuffle.FetchFailedException:Therelativeremoteexecutor(Id:21),whichmaintainstheblockdatatofetchisdead.最近在做Spark的性能优化,测试使用不同CPU核数和内存对计算性能的影响,由于是在测试集群进行测试的,硬件配置比生产上面的要少和......
  • Idea远程debug调试本地代码 Remote JVM Debug
    如果项目太大本地启动不了,或者假设你项目是微服务项目依赖太多,你写了个功能后,想本地启动debug调试又不方便,此时可以用一个idea远程debug神奇。实现访问测试环境,回调到你本地启动的代码。1,准备一个springboot项目什么都不用配置2,idea设置RemoteJVMDebug端口随便设置就行......
  • ClickHouse数据表迁移实战之-remote方式
    1引言ClickHouse是一个用于联机分析(OLAP)的列式数据库管理系统(DBMS)。我们内部很多的报表、数据看板都基于它进行开发。今天为大家带来remote方式的ClickHouse数据表迁移的完整过程介绍,如有错误,还请各位大佬指正。以下sql语句为测试使用,如需使用请根据实际情况修改。2背景......
  • Remote Procedure Call (RPC) Runtime(远程过程调用运行时)是一个在计算机网络中的通信
    RemoteProcedureCall(RPC)Runtime(远程过程调用运行时)是一个在计算机网络中的通信协议,它允许在不同的进程或计算机之间进行通信和交互。RPCRuntime是Windows操作系统中用于支持远程过程调用的关键组件。RPCRuntime在Windows操作系统中的路径通常为:C:\Windows\System3......
  • 远程桌面客户端(Remote Desktop Client)是一种用于远程连接到另一台计算机的应用程序。
    远程桌面客户端(RemoteDesktopClient)是一种用于远程连接到另一台计算机的应用程序。它允许用户通过网络连接到远程计算机,并在本地计算机上使用远程计算机的桌面环境和应用程序。以下是关于远程桌面客户端的一些重要信息:功能:远程桌面客户端提供了许多功能,包括:连接到远程计算机:通......
  • Remote Desktop Manager 2023(远程桌面管理)
    RemoteDesktopManager是一款非常好用的远程桌面管理器,主要用于管理所有远程连接和虚拟机的小型应用程序。您可以快速添加、编辑、删除、共享、组织和查找远程连接,兼容微软的远程桌面或终端服务。使用起来非常简单,但同时是强大的,有效的。除了微软远程桌面,还可兼容终端服务、VNC、......
  • The remote SSH server rejected X11 forwarding request.“远程SSH服务器拒绝X11转发
       启动kkFileView后弹出提醒无法正常访问服务器, 重启服务器时,需要安装出现如下提醒方法一、 X11forwarding依赖xorg-x11-xauth软件包,需要先安装xorg-x11-xauth软件包。1.使用Xshell执行下面代码[root@VM-4-11-centos~]#yuminstallxorg-x11-xauth  ......
  • BUUCTF:[INSHack2017]remote-multimedia-controller
    https://buuoj.cn/challenges#[INSHack2017]remote-multimedia-controllerremote-media-controler.pcap流量包中发现一个长度很大的包,里面有一串base64,解了一下发现是套娃,直接用脚本importbase64withopen('base64.txt','r')asfile:codestr=file.read()try:......
  • VirtualAllocEx;WriteProcessMemory;CreateRemoteThread
    /*structStrParam{ HWNDhPwdEdit; unsignedintnLenth; char*buff;};//计算器为目标进程。staticDWORDWINAPIMyFunc(LPVOIDpData){//dosomething StrParam*param=(StrParam*)pData; HWNDhPwdEdit=param->hPwdEdit; char*buff=param->buff; ......
  • Git:解决报错:fatal: The remote end hung up unexpectedly
    问题描述:Git在推送项目时报错:fatal:Theremoteendhungupunexpectedly。问题原因:推送的文件太大。解决方法:1.修改设置gitconfig文件的postBuffer的大小。(设置为500MB)$gitconfig--localhttp.postBuffer524288000注:--local选项指定这个设置只对当前仓库生效。......