httpwebresponse

reading HttpwebResponse json response, C#

走远了吗. 提交于 2019-11-30 02:57:38
In one of my apps, I am getting the response from a webrequest. The service is Restful service and will return a result similar to the JSON format below: { "id" : "1lad07", "text" : "test", "url" : "http:\/\/twitpic.com\/1lacuz", "width" : 220, "height" : 84, "size" : 8722, "type" : "png", "timestamp" : "Wed, 05 May 2010 16:11:48 +0000", "user" : { "id" : 12345, "screen_name" : "twitpicuser" } } and here is my current code: byte[] bytes = Encoding.GetEncoding(contentEncoding).GetBytes(contents.ToString()); request.ContentLength = bytes.Length; using (var requestStream = request

Authentication failed because the remote party has closed the transport stream exception when getting a response from webservice

独自空忆成欢 提交于 2019-11-30 01:15:37
I am calling a third party service and when I ask for a response it throws out an exception that says "Authentication failed because the remote party has closed the transport stream exception". I think that there is a problem in sending credentials. I have even tried supplying new credentials. Here is the full code string get_url = "https://**.*******.com/com/******/webservices/public_webservice.cfc?wsdl&Method=CreateUser&SiteID=**&WSPassword=******&UserName=******"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(get_url); request.MaximumAutomaticRedirections = 4; request

WebRequest - Prevent redirection

微笑、不失礼 提交于 2019-11-29 16:56:41
I am using a WebRequest to read an HTML site. The server seems to be redirecting my request. My Code is similar to the following: String URI = "http://www.foo.com/bar/index.html" WebRequest req = WebRequest.Create(URI); WebResponse resp = req.GetResponse(); StreamReader sr = new StreamReader(resp.GetResponseStream()); String returnedContent = sr.ReadToEnd(); When I check the content of the returnedContent it contains the content from a redirection like "http://www.foo.com/FOO_BAR/index.html". I am sure my requested URL exists since it is part of the recieved response (as an IFrame). Is there a

HttpWebResponse LastModified

谁都会走 提交于 2019-11-29 15:14:41
Is the HttpWebResponse.LastModified accurate? Is it always present? My project is to create a sort of a focused web crawler and I am stucked if I will use the hash value of a resource or just the HttpWebResponse.LastModified property to check the resource's "freshness". Using the hash value means streaming the resource every time it's checked. This has a big impact on overall performance. If I will just check the HttpWebResponse.LastModified, is it accurate? HttpWebResponse.LastModified returns the value of the HTTP Last-Modified response header. HTTP response headers are set by the HTTP

Show a message after sending a file to download

試著忘記壹切 提交于 2019-11-29 12:59:39
I want to update something on my aspx page, after I send a file to be downloaded. (Some error messages shown before.). I believe it's not possible, but would you provide me a solution? Here is the code to send the file to download: Response.ContentType = "Application/zip"; Response.AddHeader("Content-Disposition", "attachment; filename=" + e.CommandArgument); Response.BinaryWrite(fileStream.ToArray()); Response.Flush(); Response.Close(); Response.End(); Editing to clarify: I also believe that there is no logical solution. However, there could be a Javascript trick which I am not aware of. That

HttpWebRequest and HttpWebResponse shows old data

萝らか妹 提交于 2019-11-29 12:27:54
After updating the data, when the webservice is called, it still fetches old data. New data is loaded only when I logout of the app and then login again. protected async override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); parameterValue = this.NavigationContext.QueryString["parameter"]; Uri UserDetailUrl = new Uri(Constants.WebService.ws_single_user + "?user_id=" + parameterValue); HttpWebRequest UserDetailRequest = (HttpWebRequest)HttpWebRequest.Create(UserDetailUrl); HttpWebResponse UserDetailResponse = (HttpWebResponse)await

Error (HttpWebRequest): Bytes to be written to the stream exceed the Content-Length bytes size specified

柔情痞子 提交于 2019-11-29 09:47:42
I can't seem to figure out why I keep getting the following error: Bytes to be written to the stream exceed the Content-Length bytes size specified. at the following line: writeStream.Write(bytes, 0, bytes.Length); This is on a Windows Forms project. If anyone knows what is going on here I would surely owe you one. private void Post() { HttpWebRequest request = null; Uri uri = new Uri("xxxxx"); request = (HttpWebRequest)WebRequest.Create(uri); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; XmlDocument doc = new XmlDocument(); doc.Load("XMLFile1.xml");

Concurrency Limit on HttpWebRequest

前提是你 提交于 2019-11-29 09:05:24
问题 I am writing an application to measure how fast I can download web pages using C#. I supply a list of unique domain names, then I spawn X number of threads and perform HTTPWebRequests until the list of domains has been consumed. The problem is that no matter how many threads I use, I only get about 3 pages per second. I discovered that the System.Net.ServicePointManager.DefaultConnectionLimit is 2, but I was under the impression that this is related to the number of connections per domain.

C#: “Using” Statements with HttpWebRequests/HttpWebResponses

限于喜欢 提交于 2019-11-29 03:05:32
Jon Skeet made a comment (via Twitter) on my SOApiDotNet code (a .NET library for the pre-alpha Stack Overflow API): @maximz2005 One thing I've noticed just from browsing the source quickly: you don't disposed (sic) of WebResponses. "using" statements FTW. He indicates that I need to wrap these Web sessions in "using" statements. However, I have a question about this: should I wrap the whole thing, starting with the HttpWebRequest , or should I create the WebRequest outside of the "using" statement and then wrap the Response inside ? I have a feeling that the difference is that, in the former,

powershell httpwebrequest GET method cookiecontainer problem?

旧街凉风 提交于 2019-11-29 00:00:45
I'm trying to scrape a website that has user authentication. I am able to do a POST to send my login and stores a cookie. However, after the login I get a 403 error when trying to access the protected page. $url = "https://some_url" $CookieContainer = New-Object System.Net.CookieContainer $postData = "User=UserName&Password=Pass" $buffer = [text.encoding]::ascii.getbytes($postData) [net.httpWebRequest] $req = [net.webRequest]::create($url) $req.method = "POST" $req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" $req.Headers.Add("Accept-Language: en-US") $req.Headers