Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Canonical HTTP POST code?

I've seen so many implementations of sending an http post, and admittedly I don't fully understand the underlying details to know what's required.

What is the succinct/correct/canonical code to send an HTTP POST in C# .NET 3.5?

I want a generic method like

public string SendPost(string url, string data)

that can be added to a library and always used for posting data and will return the server response.

like image 646
User Avatar asked Sep 24 '09 04:09

User


People also ask

What is my canonical URL?

A canonical URL is the URL of the best representative page from a group of duplicate pages, according to Google. For example, if you have two URLs for the same page (such as example.com? dress=1234 and example.com/dresses/1234 ), Google chooses one as canonical.

What is canonical request?

A canonical request is a string that represents a specific HTTP request to Cloud Storage. You use a canonical request along with a cryptographic key, such as an RSA key, to create a signature that is then included in the actual request as authentication.

How do I fix my canonical URL?

There are two main ways to fix canonical issues on a website: by implementing 301 redirects, and/or by adding canonical tags to your site's pages to tell Google which of several similar pages is preferred. The right option depends on the canonical issue you're trying to resolve.

What is a canonical identifier?

The canonical ID uniquely identifies the object to which the canonical document refers. In other words, the canonical ID in a canonical document serves the same purpose that the native ID does for a native document from one of your resources.


1 Answers

I believe that the simple version of this would be

var client = new WebClient();
return client.UploadString(url, data);

The System.Net.WebClient class has other useful methods that let you download or upload strings or a file, or bytes.

Unfortunately there are (quite often) situations where you have to do more work. The above for example doesn't take care of situations where you need to authenticate against a proxy server (although it will use the default proxy configuration for IE).

Also the WebClient doesn't support uploading of multiple files or setting (some specific) headers and sometimes you will have to go deeper and use the

System.Web.HttpWebRequest and System.Net.HttpWebResponse instead.

like image 52
Patrick Klug Avatar answered Sep 29 '22 11:09

Patrick Klug