xml – 你如何做一个HTTP Put?
我们有这个软件有一个webservices组件。
现在,这个系统的管理员来找我,想要通过使用webservices组件将数据导入系统。 所以,我去阅读文档,试图把这个东西,我看到这样的东西: Click here to see what I’m talking about (this looks best in firefox,chrome,& safari) 该文档提供了使用HTTP动词(如GET,POST,PUT,DELETE)与系统交互的示例。但在我有限的经验,我从来没有必须发送HTTP PUT或DELETE。 你怎么做呢?我已经构建了具有method =“post”或method =“get”的HTML表单,并且请求发送到action属性(action =“someResource”)中指定的任何内容。但我真的不知道该怎么做这个PUT的东西。 如果我不得不猜测,我将需要构建一个应用程序,创建某种HTTP请求对象,并设置它的所有属性,并以某种方式包括我想要输出到RESOURCE(I am trying to use REST terminology,which is something else is very new to me)的数据。然后我会使用我的编程语言和blah blah blah发送请求。我只是猜测这个。请提供一些帮助! 我认为我是一个web开发人员,因为我知道像XHTML,CSS,JavaScript等等,但它开始看起来像我不知道任何关于web的基础(HTTP)。 编辑 PS:我大多用.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,arr.Length); dataStream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string returnString = response.StatusCode.ToString(); Console.WriteLine(returnString); } } 更新:现在在System.Net.Http(available as a NuGet package)中有一个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); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |