Tag: httpwebrequest

WebRequest遵循重定向

我有一个页面(url a),它使用WebRequest以编程方式提交表单。 接受表单请求的页面会执行大量内容,然后重定向到另一个页面(url b) 是否有可能执行webrequest(读取,处理和重定向表单请求),然后使当前页面(url a)重定向到webrequest结束位置(url b)。 我现在有; HttpWebRequest myRequest = (HttpWebRequest)HttpWebRequest.Create(url + postVars); myRequest.AllowAutoRedirect = true; HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse(); myRequest.AllowAutoRedirect = true; // Read response stream StreamReader myStream = new StreamReader(myResponse.GetResponseStream()); string response = myStream.ReadToEnd(); myResponse.Close(); 这一切都运行正常,除了myResponse.Close()后,一切都按预期发生,我仍然在url a,而不是url b,即请求的页面仍然是活动页面 关于我哪里出错的任何想法? 或者更好的想法? 我需要能够。 打开页面a 以编程方式将表单提交给模块b(另一页) 被重定向到页面c(其基于模块b的重定向) 那有意义吗? 提前致谢。

随机请求已中止:无法创建SSL / TLS安全通道。 返回的代码= MessageAltered

在大约一千个HTTPS请求中的一个中,抛出以下exception: System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel. at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request) at System.Net.WebClient.DownloadString(Uri address) System.Net中的日志如下所示: 2016-09-20 15:10:17.1031 | INFO | 72 | System.Net | [2688] Associating HttpWebRequest#37618637 with ServicePoint#28841767 2016-09-20 15:10:17.1031 | INFO | 72 | System.Net | [2688] Associating Connection#16407032 with HttpWebRequest#37618637 2016-09-20 15:10:17.1031 | INFO | 72 […]

ASP.NET MVC3和Google Checkout入门:拿2

这是对以下内容的跟进: https : //stackoverflow.com/questions/6285578/getting-started-with-asp-net-mvc3-google-checkout 现在我终于开始了解Google Checkout API的用途。 我决定在服务器端做所有事情。 所以我写了一些代码,但我无法成功调用API。 这是我的代码: var str = string.Format(“{0}:{1}”, MERCHANT_ID, MERCHANT_KEY); var auth = EncodeTo64(str); var request = WebRequest.Create(“https://sandbox.google.com/checkout/api/checkout/v2/requestForm/Merchant/747839340759259”); ((HttpWebRequest) request).Accept = “application/xml;charset=UTF-8”; request.Headers.Add(“Authorization”, “Basic ” + auth); request.ContentType = “application/xml;charset=UTF-8”; request.Method = “POST”; string postData = “_type=hello”; byte[] byteArray = Encoding.UTF8.GetBytes(postData); request.ContentLength = byteArray.Length; Stream dataStream = request.GetRequestStream(); dataStream.Write(byteArray, […]

保持会话活着C#

我正在使用HttpWebRequest登录网站并获取会话cookie。 我的应用程序刮擦某些页面,最终变为空闲,导致会话死亡。 什么是防止这种情况的良好方法 – 只是好奇 – 网络浏览器如何做到这一点?

WebRequest不包含Windows 10 Universal App的“GetResponse”定义

我在GitHub上下载一个控制台应用程序,工作正常。 但我想将此C#控制台应用程序转换为通用Windows 10应用程序。 Visual Studio上的错误 : Web Request does not contain a definition for… 这是代码: private AccessTokenInfo HttpPost(string accessUri, string requestDetails) { //Prepare OAuth request WebRequest webRequest = WebRequest.Create(accessUri); webRequest.ContentType = “application/x-www-form-urlencoded”; webRequest.Method = “POST”; byte[] bytes = Encoding.ASCII.GetBytes(requestDetails); webRequest.ContentLength = bytes.Length; using (Stream outputStream = webRequest.GetRequestStream()) { outputStream.Write(bytes, 0, bytes.Length); } using (WebResponse webResponse […]

当文件太大时,C#HttpWebResponse contentlength = -1

我从烂番茄网站获得了json格式的字符串。 我的代码看起来像 HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(url); webRequest.Method = “GET”; webRequest.ContentType = “application/json”; HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse(); using(StreamReader reader = new StreamReader(response.GetResponseStream())) { //Code I’m using the reader with } 当我运行一个返回1-4电影的电影搜索时,它运行正常。 但是,如果我尝试获得5或更多的结果,它将无法工作。 webResponse内容长度为-1。 当我返回4部电影的结果时,内容长度为7,449。

发出http post请求以在WP7中发送JSON文件

我想JSON file from my WP7 device to my local server发送一个JSON file from my WP7 device to my local server 。 在iOS上,我使用了ASIHttpRequest库,我所做的是: //send json file , using ASIHttpClass NSURL *url = [NSURL URLWithString:urlStr]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; request.timeOutSeconds = TIME_OUT_SECONDS; [request setRequestMethod:@”PUT”]; NSString *credentials= [self encodeCredentials]; [request addRequestHeader:@”Authorization” value:[[NSString alloc] initWithFormat:@”Basic %@”,credentials]]; [request addRequestHeader:@”Content-Type” value:@”application/json; […]

C#如何强制重用经过身份validation的Http连接?

我无法重复使用我的Http连接。 HttpWebRequest.KeepAlive设置没有区别。 我发现这篇文章说如果你有NTLM身份validation,那么使用UnsafeAuthenticatedConnectionSharing = true。 所以我将它设置为true并且仍然具有相同的TCP连接群,并且没有类似于重用.. 有什么想法吗? 对不起,我不知道什么是pastebin。 这是日志的片段我做了2次调用服务。 出于某种原因的第一次呼叫是在没有身份validation的情 响应是未授权和连接:关闭。 然后它由系统重新提交,但不再保持活动状态,响应正常,但仍然是Connection:Close。 不幸的是,出于安全原因,我无法粘贴整个日志。 System.Net Information: 0 : [5988] Associating HttpWebRequest#64923656 with ConnectStream#51393439 System.Net Information: 0 : [5988] HttpWebRequest#64923656 – Request: GET /v1.0/xxxxxx/xxxx/ HTTP/1.1 System.Net.Sockets Verbose: 0 : [5988] Socket#52727599::Send() System.Net.Sockets Verbose: 0 : [5988] Data from Socket#52727599::Send System.Net.Sockets Verbose: 0 : [5988] 00000000 : … […]

来自C#客户端的Apache NTLM Auth不能与自定义的NetworkCredentials一起使用

我有一个办公室插件,使用HttpWebRequest连接服务。 在域内我通过CredentialCache.DefaultNetworkCredentials所以一切都很好。 在域外,用户需要提供用户名,域和密码。 这不起作用。 代码的某些部分: CookieContainer cookies = new CookieContainer(); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = WebRequestMethods.Http.Post; request.AllowAutoRedirect = true; request.CookieContainer = cookies; // provide session cookie to handle redirects of login controller of the webservice if (isWindowAuthentication) // isWindowAuthentication is set earlier by config { if (Common.UserName.Length > 0) { string[] domainuser; string username; […]

如何使用.Net / Parse.com发送API凭据和用户名/密码? (PHP到C#)

我正在尝试创建一个允许我的用户登录并查看其数据的网页。 数据托管在Parse.com上,将其公开为REST API。 我正在使用asp.net / C#来访问它,并且可以通过使用他们的API密钥和应用程序密钥来完成所有操作。 但是,我需要从C#中的文档编写这个PHP代码的版本… 为此,请使用用户名和密码作为URL编码参数向/ 1 / login端点发送GET请求: curl -X GET \ -H “X-Parse-Application-Id: ${APPLICATION_ID}” \ -H “X-Parse-REST-API-Key: ${REST_API_KEY}” \ -G \ –data-urlencode ‘username=cooldude6’ \ –data-urlencode ‘password=p_n7!-e8’ \ https://api.parse.com/1/login 现在我被困在这里…我尝试过的任何东西都会返回一个HTTP 400,比如这段代码… [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public static string ParseAuthenticate(string strUserName, string strPassword ) { var httpWebRequest = (HttpWebRequest)WebRequest.Create(“https://api.parse.com/1/login”); httpWebRequest.ContentType = “application/x-www-form-urlencoded”; httpWebRequest.Headers.Add(“username:” […]