Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a popular C# library for working HTTP? Eg simplifing working with httpwebrequest etc [closed]

is there a popular C# library for working HTTP? Eg simplifing working with httpwebrequest etc

For example doing http file upload with some parameters requires many lines and knowledge of Http protocol content format etc. WebClient itself do not do it.

So being new, is there a well know library that c# developers use here?

Thanks

like image 921
Greg Avatar asked Dec 05 '09 23:12

Greg


People also ask

Is C still popular?

Despite the prevalence of higher-level languages, C continues to empower the world. The following are some of the systems that are used by millions and are programmed in the C language.

What is more popular C or C++?

At the professional level, C++ is the far more common language worldwide. As mentioned earlier, many programming opportunities in the workforce require knowledge of C++ for consideration. More applications are written entirely in C++, and it's rare to find a program written in just C.

Why is C getting more popular?

One of the very strong reasons why C programming language is so popular and used so widely is the flexibility of its use for memory management. Programmers have opportunities to control how, when, and where to allocate and deallocate memory.


4 Answers

Web forms are submitted in one of two formats: application/x-www-form-urlencoded and multipart/form-data.

WebClient provides a very simple and convenient way to upload any kind of data to a website. In case of application/x-www-form-urlencoded all you have to do is to provide a NameValueCollection. In case of multipart/form-data, AFAIK, you have to create the request data yourself (which may include both files and name value pairs).


application/x-www-form-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 sets the HTTP method to "POST" and the Content-Type to "application/x-www-form-urlencoded", URL-encodes formData and uploads it to the specified uriString.


multipart/form-data

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);

This sets the Content-Type to "multipart/form-data" with the boundary used in the request data. WebClient.UploadData sets the HTTP method to "POST" and uploads the byte array to the uriString. The request data in this example contains a file file1.dat and a form parameter submit-name which is set to Larry. The format is described in RFC2388.

like image 148
dtb Avatar answered Nov 13 '22 02:11

dtb


WebClient will do it. Like:

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

If this is not enough, be more specific. What 'parameters' do you mean?

like image 34
Henk Holterman Avatar answered Nov 13 '22 02:11

Henk Holterman


Are you looking for an Ajax library, a file upload control, or both, or neither? Check out the AjaxToolkit's AsyncFileUpload.

like image 22
cdonner Avatar answered Nov 13 '22 01:11

cdonner


this is best answer I could determine so far:

Here's a link I found that gets close to what I was thinking of. This solves my specific requirement, however doesn't seem to be overly broad in terms of methods. Perhaps these are just the key helper methods that are required mostly above/beyond basic WebClient / HttpWebRequest classes suport? Anyway if anyone knows of a popular c# HTTP library is better known than this let me know please. Else for the moment this link is the best I can find so far that answers my questions. Thanks for all the comments to-date.

like image 39
Greg Avatar answered Nov 13 '22 03:11

Greg