HTTP Put은 어떻게합니까?
웹 서비스 구성 요소가있는이 소프트웨어가 있습니다.
이제이 시스템의 관리자가 웹 서비스 구성 요소를 사용하여 시스템으로 데이터를 가져 오려고합니다.
그래서 나는 이것을 이해하기 위해 문서를 읽으 러 갔고 다음과 같은 것을보고 있습니다.
이 문서는 GET, POST, PUT, DELETE와 같은 HTTP 동사를 사용하여 시스템과 상호 작용하는 예를 제공합니다. 그러나 제한된 경험으로 HTTP PUT이나 DELETE를 보낼 필요가 없었습니다.
어떻게하나요? method = "post"또는 method = "get"이있는 HTML 양식을 작성했으며 요청은 action 속성 (action = "someResource")에 지정된 모든 항목으로 전송됩니다. 하지만 저는이 PUT로 무엇을 해야할지 모르겠습니다.
추측해야한다면 일종의 HTTP 요청 객체를 생성하고 모든 속성을 설정하고 어떻게 든 RESOURCE에 PUT하려는 데이터를 포함하는 애플리케이션을 빌드해야합니다 (
나는 XHTML, CSS, JavaScript 등을 알고 있기 때문에 웹 개발자라고 생각했지만 웹의 기초 (HTTP)에 대해 전혀 모르는 것처럼 보이기 시작했습니다.
편집하다
추신 : 주로 .net으로 프로그래밍합니다. 따라서 .net의 모든 예제는 꽤 멋질 것입니다.
다음은 HttpWebRequest를 사용하는 C # 예제입니다.
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);
}
}
업데이트 : 이제 System.Net.Http ( NuGet 패키지로 사용 가능) 에 HttpClient 클래스 가있어이 작업을 좀 더 쉽게 수행 할 수 있습니다.
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);
}
}
FORM 태그는 GET 및 POST 동사 만 지원하고 링크는 GET 요청 만 수행하므로 PUT 및 DELETE에서는 AJAX를 사용하고 XMLHttpRequests를 만들어야 할 수 있습니다.
jQuery 사용 :
$.ajax( {
url: '/controller/action',
type: 'PUT',
data: function() { ...package some data as XML },
dataType: 'xml',
... more options...
);
The note on the jQuery ajax options page warns that some browsers don't support PUT and DELETE for the request type. FWIW, I've never used PUT but have used DELETE in IE and FF. Haven't tested in Safari or Opera.
Here is how to do it in CURL: How to Use cURL to Test RESTful Rails
Or...you can definitely use an HTML form. If the app is truly RESTful, it will understand the REST actions and only let you perform certain actions based on the method you use.
You can't PUT using an HTML form (the spec defines only GET/POST for forms).
However any HTTP API should allow you to PUT, in the same way that it allows you to GET or POST. For example, here's the Java HTTPClient documentation, which details PUT alongside all the other HTTP verbs.
I don't know which language you're using, but I think it's going to be pretty trivial to write an app to perform an HTTP PUT.
I found this really cool piece of free software called RESTClient.
It lets you interact with HTTP resources using various verbs, manually setting headers and the body, setting authentication info, ssl, running test scripts, etc.
This will help me to figure out how to interact with our "webservices" software which is really just a RESTful API to the software's database.
Test the api as a chrome extension https://chrome.google.com/webstore/detail/fdmmgilgnpjigdojojpjoooidkmcomcm
Here is a tool that lets you drag and drop to PUT files
"Now, the administrator of this system has come to me, wanting to import data into the system by using the webservices component."
Web services have little to do with HTML forms.
Web services requests are either done from Javascript (e.g., as Ajax) or they're done from your application programs.
You would write a C# or VB program that used HTTP to do a Put to the given web services URL with the given set of data.
Here, for instance, is some sample VB code: http://developer.yahoo.com/dotnet/howto-rest_vb.html#post
Replace the method string of "POST" with "PUT".
How about giving libcurl.NET a try: http://sourceforge.net/projects/libcurl-net/
Just a headsup some network admins block puts for various reasons. So you may have to use a POST instead of PUT. Check with your operations.
PUT and DELETE are not part of HTML4, but are included in the HTML5 specifications. For this reason, most popular browsers don't have good support for them, since they focus on HTML4. However, they are definitely part of HTTP and always have been. You do a PUT using some non-browser client, or using a form in an HTML5-ready browser.
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
참고URL : https://stackoverflow.com/questions/812711/how-do-you-do-an-http-put
'Programing' 카테고리의 다른 글
이론적으로 C ++ 구현이 두 함수 인수의 평가를 병렬화 할 수 있습니까? (0) | 2020.11.09 |
---|---|
Timely와 같은 아름답고 세련된 앱을 만드는 방법 (0) | 2020.11.09 |
Chrome / Chromium 및 Safari에서 끌어서 놓기 파일 업로드? (0) | 2020.11.09 |
Varargs Java 모호한 호출 (0) | 2020.11.09 |
포인터에 메모리 할당 여부 확인 (0) | 2020.11.09 |