Tag: httpwebrequest

HttpWebRequest对每个主机的2个连接的限制是否适用于HttpClient?

如果每个主机的2个连接的(默认)速率限制适用于System.Net.Http.HttpClient,是否有人确信。 请说明您的信息来源以及是否可以像这样增加此限制,或者是否有更好/更简单的方法。 此外,是否有限制器实施? 例如每分钟40个电话? 有一篇关于在这里使用Reactive Extensions的限制策略的文章,但我想知道是否有一个HttpClient方法来做到这一点。

C#WebClient – 查看源代码问题

我正在使用C#WebClient将登录详细信息发布到页面并阅读所有结果。 我试图加载的页面包括flash(在浏览器中,它转换为HTML)。 我猜它是闪存避免被搜索引擎捡起来??? 我感兴趣的flash只是文本(不是图像/video)等,当我在firefox中“查看选择源”时,我确实在HTML中看到了我想看的文本。 (有趣的是,当我查看整个页面的源代码时,我看不到HTML中的文本,我想看到。这可能是相关的吗?) 目前,在我发布了我的登录详细信息并将HTML加载回来后,我看到的页面没有显示flash HTML(好像我已经查看了整个页面的源代码)。 提前致谢, 吉姆 PS:我应该指出POST实际上正在运行,我的登录成功。

使用C#和WebRequest上传图像?

这是Python中的工作代码(使用cURL): #!/usr/bin/python import pycurl c = pycurl.Curl() values = [ (“key”, “YOUR_API_KEY”), (“image”, (c.FORM_FILE, “file.png”))] # OR: (“image”, “http://example.com/example.jpg”))] # OR: (“image”, “BASE64_ENCODED_STRING”))] c.setopt(c.URL, “http://imgur.com/api/upload.xml”) c.setopt(c.HTTPPOST, values) c.perform() c.close() 这是我在C#中所拥有的: public void UploadImage() { //I think this line is doing something wrong. //byte[] x = File.ReadAllBytes(@”C:\Users\Sergio\documents\visual studio 2010\Projects\WpfApplication1\WpfApplication1\Test\hotness2.jpg”); //If I do it like this, using […]

如何设置Accept和Accept-Language标题字段?

我可以设置Request.Content-Type = …,Request.Content-Length = … 如何设置Accept和Accept-Language? 我想上传一个文件(RFC 1867),需要创建一个这样的请求: POST /test-upload.php.xml HTTP / 1.1 主持人:example.com User-Agent:Mozilla / 5.0(Windows NT 5.2; WOW64; rv:2.0.1)Gecko / 20100101 Firefox / 4.0.1 接受:text / html,application / xhtml + xml,application / xml; q = 0.9,* / *; q = 0.8 Accept-Language:tr-tr,tr; q = 0.8,en-us; q = 0.5,en; q = 0.3 Accept-Encoding:gzip,deflate Accept-Charset:ISO-8859-9,utf-8; […]

通过特定的网络适配器发送HttpWebRequest

我有两个连接到我的计算机的无线网络适配器,每个都连接到不同的网络。 我想构建一种我的浏览器将连接到的代理服务器,它将从不同的适配器发送每个HTTP请求,因此网页上的加载时间会更短。 你们知道我怎么决定从哪个网络适配器发送HttpWebRequest? 谢谢 :) UPDATE 我用过这段代码: public static IPEndPoint BindIPEndPointCallback(ServicePoint servicePoint, IPEndPoint remoteEndPoint, int retryCount) { List ipep = new List(); foreach (var i in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()) { foreach (var ua in i.GetIPProperties().UnicastAddresses) ipep.Add(new IPEndPoint(ua.Address, 0)); } return new IPEndPoint(ipep[1].Address, ipep[1].Port); } private void button1_Click(object sender, EventArgs e) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(“http://whatismyip.com”); request.ServicePoint.BindIPEndPointDelegate = […]

GetRequestStream随机抛出Timeoutexception

谷歌搜索了几天后,我真的无法解决所描述的问题。 希望在这里能找到解决方案 我在同一台服务器上调用WCF服务时使用附加代码。 我在调用WebReq.GetRequestStream()中随机获得Timeout错误 当我检查netstat时,我看到连接仍然打开,所以可能有问题,但我不知道如何解决它 //request inicialization HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(url); WebReq.Method = “POST”; WebReq.ContentType = “application/json; charset=utf-8”; WebReq.ContentLength = buffer.Length; WebReq.Proxy = null; WebReq.KeepAlive = false; //also tried with true WebReq.AllowWriteStreamBuffering = false; //also tried with true //this produces an error using (Stream PostData = WebReq.GetRequestStream()) { PostData.Write(buffer, 0, buffer.Length); PostData.Close(); } //open and […]

如何使用HttpWebRequest进行摘要式身份validation?

我发现的各种文章( 1,2 )使这看起来很容易: WebRequest request = HttpWebRequest.Create(url); var credentialCache = new CredentialCache(); credentialCache.Add( new Uri(url), // request url “Digest”, // authentication type new NetworkCredential(“user”, “password”) // credentials ); request.Credentials = credentialCache; 但是,这仅适用于没有URL参数的URL。 例如,我可以下载http://example.com/test/xyz.html ,但是当我尝试下载http://example.com/test?page=xyz ,结果是400 Bad Request消息在服务器的日志中运行以下内容(运行Apache 2.2): Digest: uri mismatch – does not match request-uri 我的第一个想法是摘要规范要求从摘要哈希中删除URL参数 – 但是从传递给credentialCache.Add()的URL中删除参数并没有改变。 所以它必须是相反的方式,在.NET框架中的某个地方错误地从URL中删除参数。

如何在CookieContainer中获取cookie信息? (所有这些,不是针对特定领域)

请参阅以下代码: CookieContainer cookieJar = new CookieContainer(); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(“http://www.google.com”); request.CookieContainer = cookieJar; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); int cookieCount = cookieJar.Count; 如何在cookieJar获取cookie信息? (所有这些,不仅仅针对特定领域。) 我怎样才能添加或删除cookie呢?

HttpWebRequest.GetResponse()在第二次调用时挂起

我正在尝试使用HttpWebRequest通过HTTP获取一系列文件。 第一个请求通过正常,但第二次通过相同的代码GetResponse()挂起并超时。 WireShark显示没有为第二个请求发送HTTP流量,因此看起来这是一个API问题。 经过一些调查,我发现它与指定内容长度有关:如果我把它留下来,那么代码工作正常。 我的代码是: HttpWebRequest httpWebRequest = ConfigureRequest(); using (WebResponse webResponse = httpWebRequest.GetResponse()) // On the second iteration we never get beyond this line { HttpWebResponse httpWebResponse = webResponse as HttpWebResponse; using (Stream webResponseStream = httpWebResponse.GetResponseStream()) { if (webResponseStream != null) { // Read the stream } } statusCode = httpWebResponse.StatusCode; httpWebResponse.Close(); } 症状似乎与这个问题和这个问题非常相似,但在这两种情况下,给出的建议是处理我已经在做的WebResponse。 […]

System.Net(HttpWebRequest)跟踪而不使用文件或app.config?

我想在我的应用程序中捕获某些但不是全部的HttpWebRequest流量以进行调试。 它是由IIS托管的Web服务。 我已阅读如何:配置网络跟踪 。 这很好用,但我不希望将跟踪指向文件,因为文件系统可能存在权限问题,数据敏感性等。我想直接捕获内存中的某些东西,我随后可以检查或加密和电子邮件。 最好不要对app.config文件进行任何更改。 我尝试了以下内容,但显然我错过了将TextWriterTraceListener绑定到System.Net的步骤。 如何将System.Net流量捕获到我的StringWriter中? StringWriter sw = new StringWriter(); TextWriterTraceListener myListener = new TextWriterTraceListener(sw); Trace.Listeners.Add(myListener); HttpWebRequest req = (HttpWebRequest) WebRequest.Create(“http://www.microsoft.com”); HttpWebResponse resp = (HttpWebResponse) req.GetResponse(); Stream s = resp.GetResponseStream(); byte[] buf = new byte[4096]; while (s.Read(buf, 0, buf.Length) > 0) ; s.Close(); myListener.Flush(); sw.Flush(); 编辑:具体来说,我想在运行时做相同的操作,除了我不想输出到network.log,我希望它转到我为此目的设置的字符串缓冲区。