system.net

C# The attempted operation is not supported for the type of object referenced

…衆ロ難τιáo~ 提交于 2019-12-13 01:24:14
问题 I got this error when I tried to parse an IP address that was in string form. I was using a public dns ip address (4.2.2.2) while testing this (using the System.Net's IPAddress.Parse method). It does the parsing correctly and returns an IPAddress object. However, if I try to access the ScopeId property of this object, a SocketException is thrown with the message given in the title. I really am not able to figure out whats the problem here. When I checked the documentation of IPAddress.ScopeId

Retrieve a string containing html Document source using Task parallel

家住魔仙堡 提交于 2019-12-11 05:04:04
问题 I really hope there's someone experienced enough both with TPL & System.Net Classes and methods What started as a simple thought of use TPL on current sequential set of actions led me to a halt in my project. As I am still fresh With .NET, jumping straight to deep water using TPL ... I was trying to extract an Aspx page's source/content(html) using WebClient Having multiple requests per day (around 20-30 pages to go through) and extract specific values out of the source code... being only one

How to properly add HttpRequestHeaders using system.net.http library

耗尽温柔 提交于 2019-12-11 04:12:55
问题 I created a HttpRequestMessage with header using windows.web.http; library: var request = base.CreateHttpRequestMessage(); request.Headers.Add("SESSION", SessionId); return request; and after sending SendRequestAsync(); , I am able to get the response successfully . But in my case I need to use system.net.http; library, with same codes: var request = base.CreateHttpRequestMessage(); request.Headers.Add("SESSION", SessionId); return request; but when I am calling the SendAsync(); , I am

How to check if Web server is up? (C#)

白昼怎懂夜的黑 提交于 2019-12-10 17:37:23
问题 I am building a monitoring application to continuously monitor all aspects of my system. I was hoping to use the Ping() function to determine if the server is up but the MSDN documentation itself says that it is not the best way: A successful Ping indicates only that the remote host can be reached on the network; the presence of higher level services (such as a Web server) on the remote host is not guaranteed. Are there any other ways to do this better? 回答1: You'll need to settle on one page

Serious CookieContainer bug?

夙愿已清 提交于 2019-12-10 15:06:38
问题 Am I missing something here or is this a bug in the CookieContainer? I'm adding 3 cookies to the container and then I call the GetCookieHeader function for 2 urls: CookieContainer cc = new CookieContainer(); cc.Add(new Cookie("Cookie1", "1", "/a", "test.com")); cc.Add(new Cookie("Cookie2", "2", "/a/0/", "test.com")); cc.Add(new Cookie("Cookie3", "3", "/a/1/", "test.com")); var result1 = cc.GetCookieHeader(new Uri("http://test.com/a/1/list")); Assert.AreEqual("Cookie3=3; Cookie1=1", result1);

Using Default Credentials in System.Net.HttpClient request in UWP

為{幸葍}努か 提交于 2019-12-10 10:29:26
问题 We are porting our Windows 8.1 app to UWP and are experiencing an issue with sending default user credentials for single sign-on. It seems that credentials are not being set, despite setting UseDefaultCredentials = true on the handler. This exact code was working in Windows 8.1. using (var client = new HttpClient(new HttpClientHandler() { UseDefaultCredentials = true })) { // client._handle.Credentials is null // This call fails authentication with a 401 // and Fiddler shows no attempt to

Is it possible to convert between Socket and TcpClient objects?

╄→гoц情女王★ 提交于 2019-12-10 02:09:55
问题 Here's another C#/.NET question based merely on curiousity more than an immediate need ... If you had a Socket instance and you wanted to wrap it in the higher-level TcpClient class, is that possible and how would you do it? Conversely if you have an instance of TcpClient , is it possible to get the underlying Socket ? 回答1: If you had a Socket instance and you wanted to wrap it in the higher-level TcpClient class, is that possible and how would you do it? Socket socket = ...; TcpClient client

Can't Install System.Net.Http Package into a Windows Phone 7.1 Silverlight Project

风格不统一 提交于 2019-12-07 23:57:49
问题 I used Nuget to install the "Microsoft ASP.NET Web API Client Libraries" to get the latest System.Net.Http assembly for use in Windows Phone 7.1 XNA and Silverlight projects. It installs just fine into my WP7.1 XNA projects, but doesn't allow me to install it into the WP7.1 Silverlight projects. I even tried installing it directly from the Package Manager Console into a newly created WP7.1 Silverlight project and got this Error response: PM> Install-Package System.Net.Http Attempting to

How to detect public IP address (of router/gateway) change in .Net?

牧云@^-^@ 提交于 2019-12-07 09:18:30
问题 I am aware of the NetworkChange.NetworkAddressChanged event, but that is only for the local network interfaces. What is the best way to detect the public IP address of the gateway has changed? Presumably one has to do it by polling an external reliable address, such a google.com...? 回答1: Here's one by Akamai: http://whatismyip.akamai.com/ 回答2: If the router supports it, you could use SNMP to query for its public IP address (or, at least, when I tried to do this I had to query for all IP

System.Net.Mail reference does not exist

跟風遠走 提交于 2019-12-07 05:27:08
问题 I have a problem creating application to send email. I already have one working as a Windows Forms Application and then decided to do the same from the empty project, because I need to make a background application now. I used the System.Net.Mail namespace for that in a Windows Forms. Then added the same code to the new project. However, I get the following error: The type or namespace name 'Mail' does not exist in the namespace 'System.Net'. The 'System.Net' reference is included in the