标签: webclient

重试 Spring @HttpExchange

我使用Spring-boot-3 @GetExchangea WebClient,有时会遇到以下错误:

java.lang.IllegalStateException: Timeout on blocking read for 5000000000 NANOSECONDS
Run Code Online (Sandbox Code Playgroud)

如果使用来@GetExchange指示WebClient重试,最佳实践是什么?这个新注释没有足够的文档。

java spring webclient spring-boot

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

VB.NET中的UploadString(Post方法)不起作用

我试图将简单数据发布到某个站点,在本例中是我本地服务器上的php文件.我的VB.NET代码:

Dim W As New Net.WebClient
Dim A As String = ""

W.Encoding = System.Text.Encoding.UTF8
Dim URL As String = "http://localhost/test/p.php"
A = W.UploadString(URL, "bla=test")

MsgBox(A)
Run Code Online (Sandbox Code Playgroud)

在这里p.php:

<?
print_r($_POST);
echo "\n";
print_r($_GET);
?>
Run Code Online (Sandbox Code Playgroud)

所以,当我启动VB.NET应用程序时,它只是简单地调用p.php(GET),但POST不起作用.尝试了一切.将p.php改为其他服务器,检查php中的其他变量($ _REQUEST),使用UploadString(URL,"POST","bla = test"),使用PERL,ASP ..没有.

我正在使用.NET Framework 3.5任何想法如何使用vb.net发布数据?

vb.net post webclient uploadstring

0
推荐指数
1
解决办法
6962
查看次数

下载数据时为什么会出现UnauthorizedAccessException?

我写了这段代码从FTP服务器下载文件.当程序尝试下载并保存文件时,我收到拒绝访问错误.我尝试使用管理员权限打开程序,但它给出了同样的错误.

WebClient request = new WebClient();
request.Credentials = new NetworkCredential(txtFTPuser.Text,
                                            txtFTPpassword.Text);
/*List all directory files*/
byte[] fileData = request.DownloadData(fullDownloaPath);//dnoces.dreamhost.com
FileStream fi = File.Create(downloadTo);
fi.Write(fileData, 0, fileData.Length);
fi.Close();
MessageBox.Show("Completed!");
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

c# file-permissions webclient filestream

0
推荐指数
1
解决办法
3073
查看次数

在C#中下载图像问题.下载html而不是

我需要下载图像(验证码).是一个例子.

如果你在任何浏览器中打开该链接它会显示一个图像,但是当我试图在代码中下载该图像时,它会给我一个html页面,其中只包含指向主页的链接 - http://www.networksolutions.com/.我究竟做错了什么?以下是两个代码示例:

byte[] data = new WebClient().DownloadData(imgURL);

AND

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(imgURL);
req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
req.Headers.Add("Accept-Language", "en-us,en;q=0.5");
req.Headers.Add("Accept-Encoding", "gzip,deflate");
req.KeepAlive = true;

byte[] data;

using (HttpWebResponse response = (HttpWebResponse)req.GetResponse())
{
    using (Stream s = response.GetResponseStream())
    {
        int contentLength = (int)response.ContentLength;
        data = new byte[contentLength];

        for (int pos = 0; pos < contentLength; ++pos)
        {
            int len = s.Read(data, pos, contentLength - pos);                                            
            pos += len;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c# webclient image http httpwebrequest

0
推荐指数
1
解决办法
1046
查看次数

为什么在使用WebClient调用另一个控制器时返回500错误?

我正在测试此链接上的示例:http://msdn.microsoft.com/en-us/vs11trainingcourse_aspnetmvc4_topic5#_Toc319061802但我有500错误使用WebClient调用另一个控制器.

当我访问"http:// localhost:2323/photo/gallery直接运行,但我正在尝试使用WebClient进行操作时它返回500错误?为什么?"

   public ActionResult Index()
    {
        WebClient client = new WebClient();
        var response = client.DownloadString(Url.Action("gallery", "photo", null, Request.Url.Scheme));


        var jss = new JavaScriptSerializer();
        var result = jss.Deserialize<List<Photo>>(response);

        return View(result);
    }
Run Code Online (Sandbox Code Playgroud)

由以下异常创建的500错误:

[ArgumentNullException: Value cannot be null.
Parameter name: input]
   System.Text.RegularExpressions.Regex.Match(String input) +6411438
   Microsoft.VisualStudio.Web.Runtime.Tracing.UserAgentUtilities.GetEurekaVersion(String userAgent) +79
   Microsoft.VisualStudio.Web.Runtime.Tracing.UserAgentUtilities.IsRequestFromEureka(String userAgent) +36
   Microsoft.VisualStudio.Web.Runtime.Tracing.SelectionMappingExecutionListenerModule.OnBeginRequest(Object sender, EventArgs e) +181
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +69
Run Code Online (Sandbox Code Playgroud)

webclient asp.net-mvc-4 dotnet-httpclient

0
推荐指数
1
解决办法
2419
查看次数

下载多个文件WebClient

我正在尝试下载多个文件,但它没有像我希望的那样工作.有人可以告诉我这个剧本有什么问题,因为我已经尝试了很多东西而且真的不知道该怎么做了.

public static void DownloadFile(string url)
        {
            WebClient client = new WebClient();
            var name = url.Substring(url.LastIndexOf('/')).Remove(0, 1);
            foreach (var item in urls)
            {
                client.DownloadFile(item, "C:\\" + name);
            }
        }

        private void btnGo_Click(object sender, EventArgs e)
        {
            urls.Add("url1");
            urls.Add("url2");
            urls.Add("url3");
            Parallel.ForEach(urls,
               new ParallelOptions { MaxDegreeOfParallelism = 10 }, 
               DownloadFile);
        }
Run Code Online (Sandbox Code Playgroud)
using (var sr = new StreamReader(HttpWebRequest.Create(url).GetResponse().GetResponseStream()))
            {
                using (var sw = new StreamWriter(url.Substring(url.LastIndexOf('/'))))
                {
                    sw.Write(sr.ReadToEnd());
                }
            }
Run Code Online (Sandbox Code Playgroud)

c# webclient download

0
推荐指数
1
解决办法
9317
查看次数

WebClient.DownloadFileAsync获取不完整的内容

我正在使用WebClient.DownloadFileAsync获取一批文件.但是有些文件不完整,没有例外.

我的问题是,如何在下载的文件未完成时进行标记?没有md5校验和来验证.

代码段是:

using (WebClient client = new WebClient())
{
    Uri sUri = new Uri(sFileLink);
    client.DownloadFileAsync(sUri, myPath);
}
Run Code Online (Sandbox Code Playgroud)

.net c# webclient downloadfileasync

0
推荐指数
1
解决办法
1364
查看次数

使用WebRequest和Twilio发送消息

我需要使用Twilio服务和NetDuino发送消息.我知道有一个API允许发送消息,但它使用Rest-Sharp后面的场景与微框架不兼容.我尝试做类似下面的事情,但我得到401错误(未经授权).我在这里得到了这个代码表单(这正是我需要做的)

var MessageApiString = "https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/SMS/Messages.json";
var request = WebRequest.Create(MessageApiString + "?From=+442033*****3&To=+447*****732&Body=test");
var user = "AC4*************0ab05bf";
var pass = "0*************b";
request.Method = "POST";
request.Credentials = new NetworkCredential(user, pass);
var result = request.GetResponse();
Run Code Online (Sandbox Code Playgroud)

c# webclient twilio netduino

0
推荐指数
1
解决办法
1619
查看次数

仅当fiddler正在运行时,才能访问XML提要

我试图理解为什么只有当我打开小提琴时才能对Feed进行简单的调用.

我查看了以下链接,但似乎没有一个答案适用:

除非fiddler正在运行,否则HttpWebRequest不起作用

HttpWebRequest仅在fiddler运行时有效

http://blogs.telerik.com/fiddler/posts/13-02-28/help!-running-fiddler-fixes-my-app-

我的代码非常简单,据我所知,它应该只用xml文件的内容填充变量:

using (var client = new WebClient())
{                    
    text = client.DownloadString(path);
}
Run Code Online (Sandbox Code Playgroud)

请注意,如果我正在运行fiddler,这可以正常工作,但如果在fiddler未运行时运行它,则会因超时错误(?)而失败.

我可以直接从我的broswer访问xml文件的路径 - 因此权限/访问似乎也不是问题.

http://www.tfl.gov.uk/tfl/syndication/feeds/cycle-hire/livecyclehireupdates.xml
Run Code Online (Sandbox Code Playgroud)

Fiddler的RAW输出是:

HTTP/1.1 200 OK
Via: 1.1 varnish, 1.1 ZTMG01
Connection: Keep-Alive
Proxy-Connection: Keep-Alive
Transfer-Encoding: chunked
Age: 19
Date: Mon, 22 Dec 2014 15:23:47 GMT
Content-Type: text/xml
ETag: "dce1c05f259961aeac88cebcdfdbeebe"
Server: AmazonS3
x-amz-id-2: C6oNmRATZO4E7eNiyPhyCOhqT45Mb9Wp0XXaU8KsBQf84gYeNzM9OPAOa9YBNFsL4DGsPSEs5Cw=
x-amz-request-id: 0CE21B93AC8DDC15
Last-Modified: Mon, 22 Dec 2014 15:22:31 GMT
X-TTL-RULE: 8
X-Cacheable: Yes. Cacheable
X-TTL: 60.000
X-Backend: proxy
X-Varnish: 10.76.2.236
X-Backend-Url: http://s3-eu-west-1.amazonaws.com/tfl.pub/Serco/livecyclehireupdates.xml
X-Hash-Url: /tfl.pub/Serco/livecyclehireupdates.xml
Access-Control-Allow-Origin: * …
Run Code Online (Sandbox Code Playgroud)

c# xml webclient fiddler

0
推荐指数
1
解决办法
413
查看次数

初学者线程或调度员方向

我希望有人能指出我正确的方向.我想制作一个简单的WPF应用程序,它有一个按钮和一个文本框.我点击按钮,它开始循环下载一堆文件.我似乎无法弄清楚如何不让下载阻止UI更新.根据我的收集,我可能不得不使用一些线程代码; 但到目前为止,我发现并尝试的所有例子都不适用于我.对我应该去看和学习的任何帮助或方向都会很棒.我似乎无法弄清楚如何在每个文件下载周围输出这些textbox.text消息.

foreach (var ticker in tickers)
    {
        var url = string.Format(urlPrototype, ticker, startMonth, startDay, startYear, finishMonth, finishDay, finishYear, "d");
        var csvfile = directory + "\\" + ticker.ToUpper() + ".csv";

        tbOutput.Text += "Starting Download of : " + ticker + "\n";

        webClient.DownloadFile(url, csvfile);

        tbOutput.Text += "End Download of : " + ticker + "\n";
        numStocks++;
    }
    tbOutput.Text += "Total stocks downloaded = " + numStocks + "\n";
Run Code Online (Sandbox Code Playgroud)

c# wpf multithreading webclient

0
推荐指数
1
解决办法
136
查看次数