标签: webclient

C#摆脱WebClient中的Connection头

我正在使用WebClient()使用C#.

我正在测试发送的标头,我注意到会自动添加以下标头.

Connection : Keep-Alive
Run Code Online (Sandbox Code Playgroud)

有什么办法可以删除吗?

c# webclient

14
推荐指数
2
解决办法
1万
查看次数

使用Webclient.Uploadfile在文件上载期间获取上载进度

我有一个应用程序,使用webclient将文件上传到服务器.我想在文件上传过程中显示进度条.我将如何实现这一目标?

.net c# vb.net webclient

14
推荐指数
1
解决办法
2万
查看次数

在C#中使用WebClient.DownloadString发送POST

我知道有很多关于用C#发送HTTP POST请求的问题,但我正在寻找一种使用WebClient而不是使用的方法HttpWebRequest.这可能吗?这很好,因为这个WebClient课程很容易使用.

我知道我可以设置Headers属性以设置某些标头,但我不知道是否可以实际执行POST WebClient.

c# post webclient http httpwebrequest

14
推荐指数
2
解决办法
2万
查看次数

WebClient不会自动重定向

使用Firebug登录登录过程时,我发现它是这样的

POST //The normal post request
GET //Automatically made after the login
GET //Automatically made after the login
GET //Automatically made after the login
Run Code Online (Sandbox Code Playgroud)

使用下面的代码发出帖子请求时,它没有发出浏览器正在进行的自动GET请求.

我的WebClient处理程序

using System;
using System.Net;

namespace Test
{
    class HttpHandler : WebClient
    {
        private CookieContainer _mContainer = new CookieContainer();

        protected override WebRequest GetWebRequest(Uri address)
        {
            var request = base.GetWebRequest(address);
            if (request is HttpWebRequest)
            {
                (request as HttpWebRequest).CookieContainer = _mContainer;
            }
            return request;
        }

        protected override WebResponse GetWebResponse(WebRequest request)
        {
            var response = base.GetWebResponse(request);
            if (response …
Run Code Online (Sandbox Code Playgroud)

c# webclient

14
推荐指数
2
解决办法
2万
查看次数

使用WebClient或WebRequest登录网站并访问数据

我正在尝试使用WebClient/ 访问网站上的受限数据WebRequest.该网站没有官方API,所以我要做的就是填写HTML表单并将值发布到服务器,这样我就登录了.

我尝试了这个这个,但它看起来不像即将发出的请求已登录.

后一个例子更吸引人,因为我显然更喜欢WebClient,但遗产WebRequest会做.

无论如何,在第一个例子中,我认为它确实登录了,但即将到来的访问私有数据的请求返回一个页面,其中包含消息"这是仅限会员的内容".

如何WebClient永久登录?

c# forms webclient login webrequest

14
推荐指数
2
解决办法
5万
查看次数

在C#中从FTP删除文件

我的程序可以使用以下代码将文件上传到FTP服务器:

WebClient client = new WebClient();
client.Credentials = new System.Net.NetworkCredential(ftpUsername, ftpPassword);
client.BaseAddress = ftpServer;
client.UploadFile(fileToUpload, WebRequestMethods.Ftp.UploadFile, fileName);
Run Code Online (Sandbox Code Playgroud)

现在我需要删除一些文件,我不能这样做.我该怎么用而不是

client.UploadFile(fileToUpload, WebRequestMethods.Ftp.UploadFile, fileName);
Run Code Online (Sandbox Code Playgroud)

.net c# ftp webclient delete-file

14
推荐指数
2
解决办法
4万
查看次数

使用c#Webclient通过https请求html

我正在通过c#WebClient类从我无法控制的站点尝试各种html资源.当我尝试访问" https://archive.org/details/OTRR_In_The_Name_Of_The_Law_Singles " 等网址时

我收到错误:System.Net.WebException:请求已中止:无法创建SSL/TLS安全通道.

我找到的解决方案建议我使用以下代码忽略证书要求并使webclient充当浏览器,但我仍然收到同样的错误

 ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(
            delegate
            {
                return true;
            });
            using(WebClient webClient = new WebClient()) {
                webClient.Headers["User-Agent"] = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729)";
                webClient.Headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
                webClient.Headers["Accept-Language"] = "en-us,en;q=0.5";
                webClient.Headers["Accept-Encoding"] = "gzip,deflate";
                webClient.Headers["Accept-Charset"] = "ISO-8859-1,utf-8;q=0.7,*;q=0.7";
                StreamReader sr = new StreamReader(webClient.OpenRead(inputString));
}
Run Code Online (Sandbox Code Playgroud)

c# ssl https webclient

14
推荐指数
3
解决办法
5万
查看次数

HttpWebRequest或Webclient更快

我需要获取特定URL的内容.这是一个简单而直接的任务,尽管我希望尽可能高效.

WebClient或HttpWebRequest会占用更少的内存吗?哪个班级能更快地完成同样的任务?哪个类初始化时间较短?

c# webclient get httpwebrequest

14
推荐指数
1
解决办法
1万
查看次数

获取Content-Disposition参数

如何获取使用WebClient从WebAPI控制器返回的Content-Disposition参数?

WebApi控制器

    [Route("api/mycontroller/GetFile/{fileId}")]
    public HttpResponseMessage GetFile(int fileId)
    {
        try
        {
                var file = GetSomeFile(fileId)

                HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
                response.Content = new StreamContent(new MemoryStream(file));
                response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
                response.Content.Headers.ContentDisposition.FileName = file.FileOriginalName;

                /********* Parameter *************/
                response.Content.Headers.ContentDisposition.Parameters.Add(new NameValueHeaderValue("MyParameter", "MyValue"));

                return response;

        }
        catch(Exception ex)
        {
            return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
        }

    }
Run Code Online (Sandbox Code Playgroud)

客户

    void DownloadFile()
    {
        WebClient wc = new WebClient();
        wc.DownloadDataCompleted += wc_DownloadDataCompleted;
        wc.DownloadDataAsync(new Uri("api/mycontroller/GetFile/18"));
    }

    void wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
    {
        WebClient wc=sender as WebClient;

        // Try to extract the filename from …
Run Code Online (Sandbox Code Playgroud)

c# webclient httpresponse content-disposition asp.net-web-api2

14
推荐指数
3
解决办法
2万
查看次数

.NET: file uploading to server using http

I have a running-state .php script that hits a URL and uploads a single/multiple files .csv type with a unique token sent with them (in the body AFAIK). Below is the working snippet:

PHP:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

$ch = curl_init('http://demo.schooling.net/school/attendance');

$DirPath = "E:/Uploads/";

$ZKFiles=array();

if ($dh = opendir($DirPath)) 
{
    while (($file = readdir($dh)) !== false) 
    {
        if ($file == '.' || $file == '..') 
        {
            continue;
        }
        $ZKFiles[]='@'.$DirPath.$file;       
    }
    closedir($dh);
}
if(!empty($ZKFiles))
{
    // Assign POST data
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, …
Run Code Online (Sandbox Code Playgroud)

php c# asp.net-mvc webclient httpclient

14
推荐指数
1
解决办法
2993
查看次数