【发布时间】:2018-08-25 08:18:01
【问题描述】:
在 Web API 调用期间将 xml 字符串作为查询字符串中的参数传递时遇到问题。我知道它是由于特殊的字符表示。但是不知道怎么解决。 我需要传递的xml字符串是:
<tagName name="red" query="tableName <> ''" requestId="requestorName:sessionID" />
但在服务方面,唯一通过的是
<tagName name="red" query="tableName
由于传递的字符串被记录为 xml,因此我无法将 < 替换为 。请给我一个解决方案。
我将字符串附加到客户端,如下所示:
WebClient client = new WebClient();
client.Headers[HttpRequestHeader.ContentType] = "application/xml";
var param = new NameValueCollection();
param.Add("tagName", Content); //Content contains the xml string to be passed
client.QueryString = param;
client.DownloadString("http://localhost:8000/api/method");
我有一个如下的 Web API
[HttpGet]
[Route("api/getquery")]
public HttpResponseMessage method(string tagName)
{
//funtions to perform
}
Web api 捕获部分字符串。
【问题讨论】:
标签: xml rest web-services asp.net-web-api parameter-passing