1

Is there any library in dotnet that transforms a 'normal' request string to a proper request?

Something that would automate things like

 client.Headers.[HttpRequestHeader.Authorization] <- "Basic " + un + ":" + pw;
nicolas
  • 9,549
  • 3
  • 39
  • 83
  • What kind of app are you writing? – Alex Dresko Apr 16 '13 at 19:27
  • just writing a simple script, and I must be doing something wrong : there has to be a simple way to issue a simple http auth request... right now having Networkcredential, etc. – nicolas Apr 16 '13 at 19:35

2 Answers2

1

For HttpWebRequest and WebClient, there is the Credentials property. You can write:

client.Credentials = new NetworkCredential("username", "password");

Don't know of anything similar for use with HttpClient.

Jim Mischel
  • 131,090
  • 20
  • 188
  • 351
  • indeed, this works, thank you... but are there no standard dotnet class that support standard web format ? – nicolas Apr 16 '13 at 19:42
  • @nicolas: Don't know what you mean by "standard Web format." As I understand it, setting the `Credentials` property that way ends up setting the `Authorization` header in the outgoing request. – Jim Mischel Apr 16 '13 at 19:47
  • I was under the impression that everyone commonly used "prot://username:pwd@machine". At least it is pretty widespread in the unix world ! – nicolas Apr 16 '13 at 19:51
  • @nicolas: It may be widespread in the unix world, but the HTTP spec expects it in the Authorization header. – Jim Mischel Apr 16 '13 at 20:06
  • so you are saying that it tries to put conformance to standard first. and standard on the web is not defined by whatever unix has been doing for the last 30 years. man, that's belief. – nicolas Apr 16 '13 at 21:59
0

If you're just writing a script, why can't you just use curl? It works in windows. http://curl.haxx.se/download.html

Alex Dresko
  • 5,179
  • 3
  • 37
  • 57
  • Indeed, but I was already in a F# scripting environment, so was wondering what part was missing. I really thought I was missing something, and looking at other question on SO, I am not alone.. – nicolas Apr 16 '13 at 22:05