Is there a popular C # library for working with HTTP? For example, simplification of work with httpwebrequest, etc.

Is there a popular C # library for working with HTTP? For example, simplification of work with httpwebrequest, etc.

For example, downloading an HTTP file with some parameters requires a lot of lines and knowledge of the format of the contents of the Http protocol, etc. WebClient itself does not.

So, being new, is there a well-known library that C # developers use here?

thanks

+5
source share
6 answers

This is the best answer that I could determine so far:

, , . , , , . , , / WebClient/HttpWebRequest? , - # HTTP, , , . , , . .

+1

- : application/x-www-form-urlencoded multipart/form-data.

WebClient -. /x -www-form-urlencoded , , NameValueCollection. multipart/form-data, AFAIK, ( , ).


/-WWW--urlencoded

NameValueCollection formData = new NameValueCollection();
formData["q"] = "c# webclient post urlencoded";
formData["btnG"] = "Google Search";
formData["hl"] = "en";

WebClient myWebClient = new WebClient();
myWebClient.UploadValues(uriString, formData);

WebClient.UploadValues ​​ HTTP "POST", Content-Type - "application/x-www-form-urlencoded", URL- formData uriString.


< > /-

string formData = @"--AaB03x
Content-Disposition: form-data; name=""submit-name""

Larry
--AaB03x
Content-Disposition: form-data; name=""files""; filename=""file1.dat""
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64

" + Convert.ToBase64String(
  File.ReadAllBytes("file1.dat"), Base64FormattingOptions.InsertLineBreaks) + @"
--AaB03x--
";

WebClient myWebClient = new WebClient();
myWebClient.Encoding = Encoding.ASCII;
myWebClient.Headers.Add("Content-Type", "multipart/form-data; boundary=AaB03x");
myWebClient.UploadString(uriString, formData);

Content-Type "multipart/form-data" , . WebClient.UploadData HTTP "POST" uriString. file1.dat submit-name, Larry. RFC2388.

+13

WebClient . :

var c = new System.Net.WebClient();    
c.UploadFile(url, filename);

, . "" ?

+3

Ajax, , , ? AjaxToolkit AsyncFileUpload.

+2
source

Chilkat Components

http://www.example-code.com

Chilkat.HttpRequest req = new Chilkat.HttpRequest();
Chilkat.Http http = new Chilkat.Http();

bool success;

//  Any string unlocks the component for the 1st 30-days.
success = http.UnlockComponent("Anything for 30-day trial");
if (success != true) {
    MessageBox.Show(http.LastErrorText);
    return;
}

//  Build an HTTP POST Request:
req.UsePost();
req.Path = "/testPostHandler.asp";
req.AddParam("arg1","This is the value for arg1.");
req.AddParam("arg2","This is the value for arg2.");
req.AddParam("arg3","This is the value for arg3.");

//  Send the HTTP POST and get the response.  Note: This is a blocking call.
//  The method does not return until the full HTTP response is received.
string domain;
int port;
bool ssl;
domain = "www.chilkatsoft.com";
port = 80;
ssl = false;
Chilkat.HttpResponse resp = null;
resp = http.SynchronousRequest(domain,port,ssl,req);
if (resp == null ) {
    textBox1.Text += http.LastErrorText + "\r\n";
}
else {
    //  Display the HTML page returned.
    textBox1.Text += resp.BodyStr + "\r\n";
}
0
source