httpwebresponse

How can I detect if a URL is redirected to another one?

这一生的挚爱 提交于 2019-12-24 03:19:33
问题 I use this code to make a 'GET' request to urls. var request = WebRequest.Create(uri) as HttpWebRequest; request.Method = "GET"; var response = request.GetResponse() as HttpWebResponse; var status = response.StatusCode; // returns HttpStatusCode.OK So, the probelem is when a url is redirected to another one, I can't detect it. For example; url is: http://site.com that redirects to http://www.site.com but when I make a request to http://site.com it returns a HttpStatusCode.OK for it -instead

encoding issues with content in response from HttpWebRequest

谁说我不能喝 提交于 2019-12-24 00:15:14
问题 I am using a HttpWebRequest to read in a web page using the following code: var pageurl = new Uri(url, UriKind.Absolute); var request = (HttpWebRequest)WebRequest.Create(pageurl); request.Method = "GET"; request.AutomaticDecompression = DecompressionMethods.GZip; request.KeepAlive = false; request.ConnectionGroupName = Guid.NewGuid().ToString(); request.ServicePoint.Expect100Continue = false; request.Pipelined = false; request.MaximumResponseHeadersLength = 4; if (ignoreCertificateErrors) {

Read HTTPWebReponse using GetResponseStream readToEnd return strange characters

佐手、 提交于 2019-12-23 15:44:20
问题 we are reading response from HttpWebResponse and the response itself is quite normal, we think. But when we try to read the string representation of that, we only receive strange characters instead of json formatted normal chars. Can anyone please tell us what is wrong here? Any question or help is welcomed, if more informations are needed, please comment. Thanks 回答1: The response content encoding header is gzip indicating the content has been compressed by the server. Set request

checking if the method of a webservice is connecting or not

霸气de小男生 提交于 2019-12-23 02:43:15
问题 I have browsed answers for checking if a webservice is up and running or not but what if i am having couple of methods which users are accessing at other end and i am supposed to monitor if those methods are working or not continously in a scheduler? I dont want to check if the service is running but if the method is working or not. I can send some sample values to these methods and check but is there any other simpler way to check this. 来源: https://stackoverflow.com/questions/9923846

Http Post WebRequest getting timed out

折月煮酒 提交于 2019-12-23 01:20:09
问题 HttpWebRequest request = WebRequest.CreateHttp("http://www.ooredoo.mv/edirectory"); request.Method = "POST"; request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0"; request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; request.Referer = "http://www.ooredoo.mv/edirectory"; request.KeepAlive = true; request.Headers.Add(HttpRequestHeader.Cookie, "PHPSESSID=cu722i6j4kkpm8d6lbp9e3f9t7; BNES_PHPSESSID=G4HHdpBzuOW4x+zrBTytg7K3VC

C# HttpWebResponse contentlength = -1 when file too large

自作多情 提交于 2019-12-22 15:00:07
问题 I'm getting a string in a json format from the Rotten Tomatoes website. My code looks like 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 } When I run a movie search that returns 1 - 4 movies it works fine. However,

How to manitain session values during HttpWebRequest?

亡梦爱人 提交于 2019-12-22 10:27:49
问题 In my code I'm sending a HttpWebRequest to a page in my website. When request sends to this page, It doesn't maintain the Session values. Below is the code, from where I'm generating the web request: Public Overloads Shared Function ReadURL(ByVal sUrl As String) As String Dim sBody As String Dim oResponse As HttpWebResponse Dim oRequest As HttpWebRequest Dim oCookies As New CookieContainer oRequest = WebRequest.Create("http://localhost:64802/inventory/purchase_order.aspx?id=5654") oRequest

How do I get the local port number of an HttpWebRequest?

白昼怎懂夜的黑 提交于 2019-12-22 09:31:29
问题 I'm making a long-running request with an HttpWebRequest asynchronously. While the request is running, I'd like to be able to get the local port of the request (ie, the one on the client, not the server). How do I do that? I've looked at HttpWebRequest.ServicePoint.BindIPEndPointDelegate, but that just seems to allow the caller to specify the local addy/port. Ideally, I'd like to allow HttpWebRequest to pick its local port normally and then ask it what it chose. 回答1: Unfortunately, the

How do i get detailed info from a HttpWebResponse

爷,独闯天下 提交于 2019-12-22 00:36:22
问题 I'm making a post httpwebrequst, but in the HttpWebResponse im getting an error code 403 forbidden. Now that error isnt very use full to me. I then tried a testprogram (that i do not have the source code to :() and used it to make the same post, and it returned with a code 403 forbidden but also told me tha SSL was needed. So is it possible to get more "serverside"details out of a failed httpwebrequest that just the errorcode? thank you Just to clear things up. Its fine that im getting the

Read specific div from HttpResponse

给你一囗甜甜゛ 提交于 2019-12-21 05:16:20
问题 I am sending 1 httpWebRequest and reading the response. I am getting full page in the response. I want to get 1 div which is names ad Rate from the response. So how can I match that pattern? My code is like: HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create("http://www.domain.com/"); HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse(); Stream response = WebResp.GetResponseStream(); StreamReader data = new StreamReader(response); string result = data.ReadToEnd(); I am