Tag: httpwebrequest

获得Request.Headers值

非常简单我敢肯定,但是把我拉到墙上! 我在我的Web应用程序中使用了一个组件,通过添加标题“XYZComponent = true”在Web请求中标识自己 – 我遇到的问题是,您如何在视图中检查此问题? 以下不会工作: if (Request.Headers[“XYZComponent”].Count() > 0) 这不是: if (Request.Headers.AllKeys.Where(k => k == “XYZComponent”).Count() > 0) 如果尚未设置标头变量,则两者都抛出exception。 非常感激任何的帮助。

通过httpWebRequest发布数据

我需要使用来自我的应用程序(桌面)的HttpWebRequest对象将一些数据“发布”到外部网站,并通过HttpWebRequest对象将响应返回到我的应用程序。 但是,发布数据的网页上有带动态名称的文本框。 如何在HttpWebResquest获取这些文本框的名称并发布数据? 例如,当我加载页面的文本框的名字就是这样U2FsdGVkX183MTQyNzE0MrhLOmUpqd3eL60xF19RmCwLlSiG5nC1H6wvtBDhjI3uM1krX_B8Fwc但是当我刷新页面名称更改这个U2FsdGVkX182MjMwNjIzMPAtotst_q9PP9TETomXB453Mq3M3ZY5HQt70ZeyxbRb118Y8GQbgP8 。 谢谢你的任何建议。

HttpWebRequest或WebRequest – 继续下载ASP.NET

我想知道是否有办法知道服务器是否支持简历下载function,如果支持,我该如何发送恢复请求? 我正在寻找一个解决方案,我的ASP.NET页面可以从服务器下载到我的,像今天的“ rapidleech ”这样的东西,但我想检查我请求下载的服务器是否支持恢复function。

C#:使用超时下载URL

在.NET中最好的方法是什么? 我总是忘记我需要Dispose() (或using包装)。 编辑:经过很长一段时间使用WebRequest ,我发现了自定义WebClient 。 好多了。

C# – 连接:在HttpWebRequest期间未发送保持活动标头

我正在尝试发送以使用我的HttpWebRequest发送以下标头: Connection: keep-alive 但是,标头永远不会发送。 Fiddler2显示,每当我在Google Chrome中请求该页面时,都会发送标题。 但是,我的应用程序由于某种原因拒绝发送此标头。 我已将KeepAlive属性设置为true (默认情况下默认为true ),但标题仍未发送。 我正在尝试使用多个HttpWebRequests发送此标头,但它们基本上都是这样的: HttpWebRequest logIn6 = (HttpWebRequest)WebRequest.Create(new Uri(responseFromLogIn5)); logIn6.CookieContainer = cookies; logIn6.KeepAlive = true; logIn6.Referer = “https://login.yahoo.com/config/login?.src=spt&.intl=us&.lang=en-US&.done=http://football.fantasysports.yahoo.com/”; logIn6.UserAgent = “Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.220 Safari/535.1”; logIn6.Accept = “text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8”; logIn6.Headers.Add(“Accept-Encoding:gzip,deflate,sdch”); logIn6.Headers.Add(“Accept-Language:en-US,en;q=0.8”); logIn6.Headers.Add(“Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3”); logIn6.AllowAutoRedirect = false; HttpWebResponse logIn6Response = (HttpWebResponse)logIn6.GetResponse(); string responseFromLogIn6 = logIn6Response.GetResponseHeader(“Location”); […]

如何在代码中设置useUnsafeHeaderParsing

我收到以下exception: 服务器提交了协议违规。 Section = ResponseHeader Detail = CR必须后跟LF 从这个问题: HttpWebRequestError:服务器提交了协议违规。 Section = ResponseHeader Detail = CR必须后跟LF 我知道我需要将useUnsafeHeaderParsing设置为True。 这是我的代码: HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url); WebResponse myResp = myReq.GetResponse(); //exception is thrown here useUnsafeHeaderParsing是HttpWebRequestElement类的属性。 如何将其集成到上面的代码中? 非常感谢!

HttpWebRequests在Authorization标头中发送无参数URI

我正在从.NET连接到Web服务,例如: var request = (HttpWebRequest) WebRequest.Create(uri); request.Credentials = new NetworkCredential(“usr”, “pwd”, “domain”); var response = (HttpWebResponse) request.GetResponse(); 授权标头如下所示: Authorization: Digest username=”usr”,realm=”domain”,nonce=”…”, uri=”/dir”,algorithm=”MD5″,etc… ^^^^^^^^^^ 服务器返回(400)错误请求。 Chrome或IE发送的标头如下: Authorization: Digest username=”usr”, realm=”domain”, nonce=”…”, uri=”/dir/query?id=1″, algorithm=MD5, etc… ^^^^^^^^^^^^^^^^^^^^^ 我们怀疑URI的不同导致Web服务拒绝400错误的请求。 是否有可能使HttpRequest发送包含完整URI的Authorization标头?

如何为HttpWebRequest定义更积极的超时?

在可移植类库中,我有以下方法将数据发布到特定的Url。 该方法效果很好。 但是我想指定一个更积极的超时(默认为100秒)。 考虑到来自可移植类库的HttpWebRequest类没有Timeout属性,如何在超过几秒的时间内确保调用被放弃? public async Task PostAsync(Uri uri, string data) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.Method = “POST”; request.ContentType = “application/x-www-form-urlencoded”; using (Stream requestStream = await request.GetRequestStreamAsync()) { byte[] postBytes = Encoding.UTF8.GetBytes(data); requestStream.Write(postBytes, 0, postBytes.Length); } HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync(); return new HttpResponse(response.StatusCode, await new StreamReader(response.GetResponseStream()).ReadToEndAsync()); }

使用HttpWebRequest使用multipart / form-data POST数据/上传图像

我正在尝试使用ImageShack API上传图像。 要使用它,我应该使用multipart/form-data POST图像。 我这样做…… var postData = “”; var req = HttpWebRequest.Create(“http://www.imageshack.us/upload_api.php”); req.Method = “POST”; req.ContentType = “multipart/form-data”; postData += “key=my_key_here&”; postData += “type=base64&”; // get base64 data from image byte[] bytes = File.ReadAllBytes(@”D:\tmp\WpfApplication1\WpfApplication1\Images\Icon128.gif”); string encoded = Convert.ToBase64String(bytes); postData += “fileupload=” + encoded; byte[] reqData = Encoding.UTF8.GetBytes(postData); using (Stream dataStream = req.GetRequestStream()) { dataStream.Write(reqData, […]

C#HttpWebRequest底层连接已关闭:发送时发生意外错误

我一直在谷歌搜索并尝试我能找到或想到的所有解决方案。 我正在尝试加载的网站正在运行TLS1.2,我试图测试的其他几个网站也确保它不是TLS1.2问题。 其他网站装得很好。 byte[] buffer = Encoding.ASCII.GetBytes( “mod=www&ssl=1&dest=account_settings.ws” + “&username=” + username.Replace(” “, “20%”) + “&password=” + password.Replace(” “, “20%”)); ServicePointManager.MaxServicePointIdleTime = 1000; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create( “https://secure.runescape.com/m=weblogin/login.ws”); WebReq.Method = “POST”; WebReq.KeepAlive = false; WebReq.Referer = “https://secure.runescape.com/m=weblogin/loginform.ws” + “?mod=www&ssl=1&expired=0&dest=account_settings.ws”; WebReq.ContentType = “application/x-www-form-urlencoded”; WebReq.ContentLength = buffer.Length; Stream PostData = WebReq.GetRequestStream(); PostData.Write(buffer, 0, buffer.Length); […]