system.net

HttpWebRequest.UserAgent : What does it do

走远了吗. 提交于 2019-11-28 13:23:52
I read this MSDN like about it and ran its example. http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.useragent.aspx when I change the uSerAgnet to something like "blah", the output is wrong but when I use the same thing that is in the example of even when I comment out the line of code that is setting the UserASgent, the output is correct. what is UserAgent at all ? when should I set it ? How to know to what value should I set it ? thanks The User Agent is used to identify the client and operating system etc. It's most commonly used in browsers. You can used the User Agent to

Json.Net - Error getting value from 'ScopeId' on 'System.Net.IPAddress'

江枫思渺然 提交于 2019-11-28 04:57:19
I am trying to serialize an IPEndpoint object with Json.Net and I get the following error: Error getting value from 'ScopeId' on 'System.Net.IPAddress'. The cause of the error is that I am only using the IPV4 properties of the IPAddress object in the endpoint. When the Json parser tries to parse the IPv6 portion, it accesses the ScopeID property which throws a socket exception "The attempted operation is not supported for the type of object referenced" (A null would have sufficed microsoft!) I was wondering if there may be a workaround for this other than ripping everything apart and coding

Get IE's default proxy with DefaultWebProxy

╄→尐↘猪︶ㄣ 提交于 2019-11-28 04:45:23
问题 I've read through pretty much all the documentation I can find but I'm yet to find a simple working example of how to get IE's default proxy settings using DefaultWebProxy() . This code seems to compile and work but how do I then go ahead and get the proxy URI as a string? HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create("http://www.google.com"); if (WebRequest.DefaultWebProxy != null) { webRequest.Proxy = WebRequest.DefaultWebProxy; } EDIT: Since submitting this question I

Usage of EnsureSuccessStatusCode and handling of HttpRequestException it throws

℡╲_俬逩灬. 提交于 2019-11-27 18:04:00
What's the usage pattern of HttpResponseMessage.EnsureSuccessStatusCode() ? It disposes of the Content of the message and throws HttpRequestException , but I fail to see how to programmatically handle it any differently than a generic Exception . For example, it doesn't include the HttpStatusCode , which would have been handy. Is there any way of getting more info out of it? Could anyone show relevant usage pattern of both EnsureSuccessStatusCode() and HttpRequestException? The idiomatic usage of EnsureSuccessStatusCode is to concisely verify success of a request, when you don't want to handle

Kanji characters from WebClient html different from actual Kanji in website

天大地大妈咪最大 提交于 2019-11-27 15:52:22
So, I'm trying to get a portion of text from a website called Kanji-A-Day.com , but I have a problem. You see, I'm trying to get the daily kanji from the website, and I was able to narrow the HTML down to what I want, but it seems the characters are different..? What it looks like What it should look like What's even more strange is that I produced the results for the second image by copying and pasting directly from the site, so it's not a font problem. Here's the code I use for getting the character: public void UpdateDailyKanji() // Called at the initialization of a new main form { string

How do I clear System.Net client DNS cache?

Deadly 提交于 2019-11-27 13:30:27
I'm using the .NET WebRequest while changing my HOSTS file. I'm observing that System.Net doesn't honor those changes - how can I make it do so? I have a number of servers load-balanced behind a single hostname, let's say 'example.com'. I want to target several of them individually, so my program will hard-code the machine-specific IP address in my HOSTS file before sending a request to example.com: 163.56.0.34 example.com For the first server and first request, this works fine. Then my program changes the HOSTS file again: 163.56.0.48 example.com And I create a new HttpWebRequest. When I send

HttpWebRequest.UserAgent : What does it do

久未见 提交于 2019-11-27 07:38:26
问题 I read this MSDN like about it and ran its example. http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.useragent.aspx when I change the uSerAgnet to something like "blah", the output is wrong but when I use the same thing that is in the example of even when I comment out the line of code that is setting the UserASgent, the output is correct. what is UserAgent at all ? when should I set it ? How to know to what value should I set it ? thanks 回答1: The User Agent is used to

What is IP address '::1'?

夙愿已清 提交于 2019-11-27 00:41:32
I was playing with sockets on local machine with no network connection. See below: IPAddress address = IPAddress.Any; // doesn't work IPAddress address = IPAddress.Parse("::1"); // works So what is exactly ::1 IP address ? Is it the default available IP address or it's the loopback address ? what happens to above code (working line) on a machine with dedicated IP address and network connection ? EDIT: exact code is used to bind a specific IP address to socket. Here it is: ServicePoint sp = ServicePointManager.FindServicePoint(uri); sp.BindIPEndPointDelegate = new BindIPEndPoint(Bind); // here

Json.Net - Error getting value from 'ScopeId' on 'System.Net.IPAddress'

有些话、适合烂在心里 提交于 2019-11-26 19:35:27
问题 I am trying to serialize an IPEndpoint object with Json.Net and I get the following error: Error getting value from 'ScopeId' on 'System.Net.IPAddress'. The cause of the error is that I am only using the IPV4 properties of the IPAddress object in the endpoint. When the Json parser tries to parse the IPv6 portion, it accesses the ScopeID property which throws a socket exception "The attempted operation is not supported for the type of object referenced" (A null would have sufficed microsoft!)

Usage of EnsureSuccessStatusCode and handling of HttpRequestException it throws

谁说我不能喝 提交于 2019-11-26 19:16:29
问题 What's the usage pattern of HttpResponseMessage.EnsureSuccessStatusCode() ? It disposes of the Content of the message and throws HttpRequestException , but I fail to see how to programmatically handle it any differently than a generic Exception . For example, it doesn't include the HttpStatusCode , which would have been handy. Is there any way of getting more info out of it? Could anyone show relevant usage pattern of both EnsureSuccessStatusCode() and HttpRequestException? 回答1: The idiomatic