如何在服务器端从 HTTPPOST 请求加载数据?
我有一个像这样的 WebInvoke 方法;
[OperationContract]
[WebInvoke(
Method = "POST",
UriTemplate = "/go",
BodyStyle = WebMessageBodyStyle.Bare,
RequestFormat = WebMessageFormat.Xml,
ResponseFormat = WebMessageFormat.Xml
)]
string go(string name);
我这样发布数据;
System.Net.WebClient client = new System.Net.WebClient();
string reply = client.UploadString(
"http://localhost/HelloService/Service.svc/go",
"POST",
aString);
问题是如何在不使用这样的 uri 模板的情况下从 go() 方法中获取已发布消息中的数据;
UriTemplate = "/go({name})"
因为我要发送大量数据,但无法在uri模板中发送
I have a WebInvoke method like this;
[OperationContract]
[WebInvoke(
Method = "POST",
UriTemplate = "/go",
BodyStyle = WebMessageBodyStyle.Bare,
RequestFormat = WebMessageFormat.Xml,
ResponseFormat = WebMessageFormat.Xml
)]
string go(string name);
and I post the data like this;
System.Net.WebClient client = new System.Net.WebClient();
string reply = client.UploadString(
"http://localhost/HelloService/Service.svc/go",
"POST",
aString);
The question is how can I take the data from posted message in go() method without using a uri template like this;
UriTemplate = "/go({name})"
Because I want to sent large amount of data and I cannot sent it in uri template
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是解决方案;
HTTP POST 请求是;
Here is the solution;
and HTTP POST request is;
您有权访问 System.Web.HttpContext.Current 吗?
您可以尝试 System.Web.HttpContext.Current.Request.Form,或者,您似乎正在使用 XML 作为请求格式,因此您可能需要尝试从请求流加载 XElement 或 XmlDocument。
(这里可能有错误的方法,但它存在于请求对象的某个地方)
// 仅.NET 4.0
Do you have access to
System.Web.HttpContext.Current
?You could try System.Web.HttpContext.Current.Request.Form, or, it looks like you are using XML for your request format, so you may want to try loading an XElement or XmlDocument from the request stream.
(may have the wrong method here, but it exists somewhere in the request object)
// .NET 4.0 only