How do you do HTTP posting?

We have this software with the webservices component.

Now the administrator of this system came to me, wanting to import data into the system using the webservices component.

So, I went to read the documentation to try to understand this thing, and I see things like this:

Click here to see what I'm talking about (this looks best in firefox, chrome and safari) <h / "> hit>

This documentation provides examples of interacting with the system using HTTP verbs such as GET, POST, PUT, DELETE. But in my limited experience, I never had to send either HTTP PUT or DELETE.

How do you do this? I created HTML forms that have a method = "post" or method = "get", and the request is sent to everything that is specified in the action attribute (action = "someResource"). But I really don't know what to do with this thing.

If I were to guess, I would have to create an application that creates some kind of HTTP request object and sets all its properties and somehow includes the data that I want to use for RESOURCE ( I'm trying to use the REST terminology, which is completely different for me. ). Then I will send a request using my programming language and blah blah blah. I'm just thinking about it. Please, help!

I thought I was a web developer because I know things like XHTML, CSS, JavaScript, etc., but it starts to look like I don't know anything about the basics of the Internet at all (HTTP).

EDIT

PS: I program mainly with .net. So any examples in .net would be pretty awesome.

+66
rest put xml web-services
May 01 '09 at 18:51
source share
11 answers

Here is a C # example using HttpWebRequest:

using System; using System.IO; using System.Net; class Test { static void Main() { string xml = "<xml>...</xml>"; byte[] arr = System.Text.Encoding.UTF8.GetBytes(xml); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://localhost/"); request.Method = "PUT"; request.ContentType = "text/xml"; request.ContentLength = arr.Length; Stream dataStream = request.GetRequestStream(); dataStream.Write(arr, 0, arr.Length); dataStream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string returnString = response.StatusCode.ToString(); Console.WriteLine(returnString); } } 

Update : now there is an HttpClient class in System.Net.Http ( available as a NuGet package ) which makes this a little easier:

 using System; using System.Net.Http; class Program { static void Main() { var client = new HttpClient(); var content = new StringContent("<xml>...</xml>"); var response = client.PutAsync("http://localhost/", content).Result; Console.WriteLine(response.StatusCode); } } 
+22
May 01 '09 at 9:35
source

PUT and DELETE are likely to require the use of AJAX and the creation of XMLHttpRequests, since the FORM tag only supports GET and POST verbs, and links only make GET requests.

Using jQuery:

  $.ajax( { url: '/controller/action', type: 'PUT', data: function() { ...package some data as XML }, dataType: 'xml', ... more options... ); 

A note on the jQuery ajax page warns that some browsers do not support PUT and DELETE for the request type. FWIW, I never used PUT, but used DELETE in IE and FF. Not tested in Safari or Opera.

+15
May 01 '09 at 19:07
source

Here's how to do it in CURL : How to use cURL to test RESTful Rails

Or ... you can definitely use an HTML form. If the application is truly RESTful, it will understand REST actions and allow you to perform certain actions based on the method you use.

+8
May 01 '09 at 18:56
source

You cannot use PET using an HTML form (the specification defines only GET / POST for forms).

However, any HTTP API should allow you to PUT, just as it allows GET or POST. For example, here's the Java documentation HTTPClient , which details PUT along with all other HTTP verbs.

I don’t know which language you are using, but I think that writing an application to execute HTTP PUT is quite difficult.

+6
May 01 '09 at 19:07
source

I found this really cool freeware called RESTClient .

It allows you to interact with HTTP resources using various verbs, manually configure headers and body, configure authentication information, ssl, run test scripts, etc.

This will help me figure out how to interact with our "webservices" software, which is actually just a RESTful API for a software database.

+6
May 04 '09 at 19:13
source
+2
Sep 17
source

Here is a tool that allows you to drag and drop files into PUT

+1
May 01 '09 at 19:02
source

"Now the administrator of this system has come to me, wanting to import data into the system using the webservices component."

Web services have little to do with HTML formats.

Web service requests are either executed from Javascript (like Ajax, for example) or executed from your application programs.

You must write a C # or VB program that used HTTP to make a Put for a given web services URL with a given dataset.

Here, for example, is some sample VB code: http://developer.yahoo.com/dotnet/howto-rest_vb.html#post

Replace the line of the "POST" method with "PUT".

+1
May 01, '09 at 19:29
source

How about trying libcurl.NET: http://sourceforge.net/projects/libcurl-net/

+1
Feb 10 '10 at 7:01
source

Just a control unit for some of the network administrators blocks for various reasons. Therefore, you may have to use POST instead of PUT. Check your actions.

0
May 01 '09 at 18:53
source

PUT and DELETE are not part of HTML4, but are included in the HTML5 specification. For this reason, most popular browsers do not have good support for them, as they focus on HTML4. However, they are definitely part of HTTP and have always been. You are performing PUT using a non-browser client or using the form in a browser that supports HTML5.

Update: PUT and DELETE are no longer part of HTML5 for forms. See: http://www.w3.org/TR/html5/association-of-controls-and-forms.html#attr-fs-method

0
Jul 20 '09 at 10:21
source



All Articles