Tag: httpwebrequest

是否可以在.NET 4.0框架上使用TLS1.2发送HttpWebRequest

我的应用程序连接到Experian服务器,Experian将很快停止支持TLS 1.0和TLS 1.1 。 使用HTTPS所有连接必须使用TLS Version 1.2 。 我想对该问题进行一些研究,并看到在.NET 4.0 framework上使用TLS 1.2发送HttpWebRequest 如果没有,我可能需要在.NET 4.5上创建一个webservice服务并调用它的方法,如果有的话,我没有任何东西。 有人已经面临过这个问题吗?

C#httpwebrequest和javascript

我正在使用C#HttpWebRequest来获取网页的一些数据。 问题是在页面加载后使用javascript / ajax更新了一些数据,而我没有在响应字符串中获取它。 有没有办法让webrequest等到页面中的所有脚本都已完成执行? 谢谢 阿米特

C#https登录和下载文件

我已成功连接到登录页面,但是,我不确定如何登录并获取登录后面的文件。 下面是我用来连接的代码。 private static bool bypassAllCertificateStuff(object sender, X509Certificate cert, X509Chain chain, System.Net.Security.SslPolicyErrors error) { return true; } public static void Processing() { string url = “https://app/templat”; HttpWebRequest request; HttpWebResponse response; CookieContainer cookies; ServicePointManager.ServerCertificateValidationCallback = System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true); System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, cert, chain, errors) => cert.Subject.Contains(“YourServerName”)); ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(bypassAllCertificateStuff); try […]

HttpWebRequest:请求已中止:请求已取消

我一直致力于开发一种中间人应用程序,它使用一系列日期的HTTP发布请求(通常一次只有7个)将文本上传到CMS后端。 我正在使用HttpWebRequest来实现这一目标。 它似乎在第一个日期工作正常,但是当它开始第二个日期时,我得到System.Net.WebException:请求被中止:请求被取消。 我四处搜寻,发现以下重要线索: http://social.msdn.microsoft.com/Forums/en-US/netfxnetcom/thread/0d0afe40-c62a-4089-9d8b-fb4d206434dc http://www.jaxidian.org/update/2007/05/05/8 http://arnosoftwaredev.blogspot.com/2006/09/net-20-httpwebrequestkeepalive-and.html 他们并没有太多帮助。 我试过重载GetWebReuqest,但这没有意义,因为我没有使用该函数。 这是我的代码: http : //pastebin.org/115268 在成功运行至少一次后,我在第245行得到错误。 我很感激我能得到的任何帮助,因为这是我一直在努力的项目的最后一步。 这是我的第一个C#/ VS项目,所以我对任何提示持开放态度,但我想专注于首先解决这个问题。 谢谢!

获取异步HttpWebRequest的响应

我想知道是否有一个简单的方法来获得异步httpwebrequest的响应。 我已经在这里看到了这个问题但是我想要做的就是将字符串forms的响应(通常是json或xml)返回到另一个方法,然后我可以解析它/相应地处理它。 下面是一些代码: 我在这里有这两个静态方法,我认为这些方法是线程安全的,因为所有的参数都被传入并且方法没有共享的局部变量? public static void MakeAsyncRequest(string url, string contentType) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.ContentType = contentType; request.Method = WebRequestMethods.Http.Get; request.Timeout = 20000; request.Proxy = null; request.BeginGetResponse(new AsyncCallback(ReadCallback), request); } private static void ReadCallback(IAsyncResult asyncResult) { HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState; try { using (HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult)) { Stream responseStream = response.GetResponseStream(); using […]

GetResponseAsync不接受cancellationToken

似乎GetResponseAsync在Async / Await中不接受cancellationToken。 所以问题是我如何取消以下程序,只要我需要从响应中收集Cookie: using (HttpWebResponse response = (HttpWebResponse) await request.GetResponseAsync()) { cookies.Add(response.Cookies); } 实现上述目标的替代代码也是受欢迎的。

C#HttpWebRequest类型为“application / x-www-form-urlencoded” – 如何在内容体中发送’&’字符?

我正在用C#编写一个小型的API连接应用程序。 我连接到一个API,它有一个采用长字符串的方法,即日历(ics)文件的内容。 我是这样做的: HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL); request.Method = “POST”; request.AllowAutoRedirect = false; request.CookieContainer = my_cookie_container; request.Accept = “text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8”; request.ContentType = “application/x-www-form-urlencoded”; string iCalStr = GetCalendarAsString(); string strNew = “&uploadfile=true&file=” + iCalStr; using (StreamWriter stOut = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII)) { stOut.Write(strNew); stOut.Close(); } 这似乎很有效,直到我在我的日历中添加一些特定的HTML。 如果我在我的日历(或类似)中的某个地方有一个’&nbsp’,那么服务器只会获得所有数据到’&’ – 点,所以我假设’&’使得它看起来像这个点之后的任何东西属于一个新参数? 我怎样才能解决这个问题?

HttpWebRequest和C#中的表单身份validation

我是一个系统人员,目前正在做一个兼职的Web开发项目,所以我很新。 我正在尝试为www.portapower.com编写一个http客户端。 对于在网站上发布的某些项目,如果它们符合特定要求,它将打印一条消息。 在尝试访问此页面时: http://www.portapower.com/getbainfo.php?fclasscode=1&code=CB1831B.40H&fbrand=QUNFUg== 该网站将我重定向到默认注册页面: http://www.portapower.com/defaregit.php 这是我编码的片段: CookieContainer myContainer = new CookieContainer(); HttpWebRequest request = (HttpWebRequest) WebRequest.Create(“http://www.portapower.com/” + urlpart); request.Credentials = new NetworkCredential(“****”, “******”); request.CookieContainer = myContainer; request.PreAuthenticate = true; request.Method = “POST”; HttpWebResponse response = (HttpWebResponse) request.GetResponse(); Console.WriteLine(response.StatusCode); Stream resStream = response.GetResponseStream(); Console.WriteLine(resStream.ToString()); 我有用户名和密码,从浏览器使用时工作正常。 请告诉我这是否是访问经过身份validation的页面的正确方法。

如何使用C#将JSON发布到服务器?

这是我正在使用的代码: // create a request HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url); request.KeepAlive = false; request.ProtocolVersion = HttpVersion.Version10; request.Method = “POST”; // turn our request string into a byte stream byte[] postBytes = Encoding.UTF8.GetBytes(json); // this is important – make sure you specify type this way request.ContentType = “application/json; charset=UTF-8”; request.Accept = “application/json”; request.ContentLength = postBytes.Length; request.CookieContainer […]

如何在HttpWebRequest中更改原始IP

我在已分配5个IP的服务器上运行此应用程序。 我使用HttpWebRequest从网站获取一些数据。 但是当我建立连接时,我能够指定连接的5个IP中的哪一个。 HttpWebRequest是否支持此function? 如果不能,我可以从中inheritance一个类来改变它的行为吗? 我在这里需要这样的想法。 我的代码现在是这样的: System.Net.WebRequest request = System.Net.WebRequest.Create(link); ((HttpWebRequest)request).Referer = “http://application.com”; using (System.Net.WebResponse response = request.GetResponse()) { StreamReader sr = new StreamReader(response.GetResponseStream()); return sr.ReadToEnd(); }