Questions tagged [system.net]

System.Net is a namespace of the .NET framework. It provides a simple programming interface for many of the protocols used on networks today.

System.Net is a namespace of the .NET framework. It provides a simple programming interface for many of the protocols used on networks today.

References

297 questions
153
votes
3 answers

What is IP address '::1'?

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…
Xaqron
  • 29,931
  • 42
  • 140
  • 205
142
votes
5 answers

Usage of EnsureSuccessStatusCode and handling of HttpRequestException it throws

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…
G. Stoynev
  • 7,389
  • 6
  • 38
  • 49
131
votes
7 answers

Checking if HttpStatusCode represents success or failure

Let's suppose I have the following variable: System.Net.HttpStatusCode status = System.Net.HttpStatusCode.OK; How can I check if this is a success status code or a failure one? For instance, I can do the following: int code = (int)status; if(code…
Matias Cicero
  • 25,439
  • 13
  • 82
  • 154
106
votes
9 answers

Send a file via HTTP POST with C#

I've been searching and reading around to that and couldn't fine anything really useful. I'm writing an small C# win app that allows user to send files to a web server, not by FTP, but by HTTP using POST. Think of it like a web form but running on a…
gabitoju
  • 1,196
  • 2
  • 9
  • 10
59
votes
6 answers

From where do I reference a missing assembly (System.Net.Http.Formatting)?

In my Visual Studio 2013 RC project, I'm getting this err msg: "The type 'System.Net.Http.Formatting.MediaTypeFormatter' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Net.Http.Formatting,…
43
votes
2 answers

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

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…
Dinsdale
  • 617
  • 1
  • 7
  • 8
39
votes
4 answers

How do I clear System.Net client DNS cache?

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…
Bruce
  • 8,202
  • 6
  • 37
  • 49
37
votes
1 answer

C# Read (not write!) string from System.Net.Http.StringContent

I have what seems like it should be a simple question, but I can't find an answer to it anywhere. Given the following code: using System.Net.Http; ... StringContent sc = New StringContent("Hello!"); string myContent = ???; What do I…
IAmErickson
  • 373
  • 1
  • 3
  • 6
32
votes
1 answer

How to request only the HTTP header with C#?

I want to check if the URL of a large file exists. I'm using the code below but it is too slow: public static bool TryGet(string url) { try { GetHttpResponseHeaders(url); return true; } catch (WebException) { …
Jader Dias
  • 88,211
  • 155
  • 421
  • 625
27
votes
4 answers

.NET: WebBrowser, WebClient, WebRequest, HTTPWebRequest... ARGH!

In the System.Net namespace, there are very many different classes with similar names, such as: WebBrowser and WebClient WebRequest and HTTPWebRequest WebResponse and HTTPWebResponse Those are the main ones I'm curious about. What is each one's…
Maxim Zaslavsky
  • 17,787
  • 30
  • 107
  • 173
25
votes
3 answers

Update app.config system.net setting at runtime

I need to update a setting in the system.net SectionGroup of a .Net exe app.config file at runtime. I don't have write access to the original config file at runtime (I am developing a .Net dll add-in which is hosted in an exe provided by the app…
mthornal
  • 395
  • 1
  • 4
  • 9
25
votes
1 answer

UseUnsafeHeaderParsing setting in .Net Core

I used to use this setting in the full .Net framework to deal with some unsafe headers returned by a server I'm reaching out to. I…
Alessandro Di Lello
  • 1,181
  • 1
  • 9
  • 22
18
votes
4 answers

System.Net.Http NuGet package 4.3.0 reference generates System.IO.FileLoadException on System.Diagnostics.DiagnosticSource ver 4.0.0.0 reference

Description of the problem: A shared library "shared.dll" project references System.Net.Http NuGet package 4.3.0. The application that references "shared.dll" fails with System.IO.FileLoadException Could not load file or assembly…
14
votes
4 answers

Access system.net settings from app.config programmatically in C#

I am trying to programmatically access a Windows application app.config file. In particular, I am trying to access the "system.net/mailSettings" The following code Configuration config =…
Ashwin
14
votes
5 answers

Uri.AbsolutePath messes up path with spaces

In a WinApp I am simply trying to get the absolute path from a Uri object: Uri myUri = new Uri(myPath); //myPath is a string //somewhere else in the code string path = myUri.AbsolutePath; This works fine if no spaces in my original path. If spaces…
JohnIdol
  • 48,899
  • 61
  • 158
  • 242
1
2 3
19 20