【发布时间】:2017-11-24 18:35:19
【问题描述】:
我收到一条错误消息,并按照我收到的关于如何对我的请求进行编码的 API 手册进行操作。以下是我的要求..
string url = "[My url to send request to]";
string xmlrequest = "<serv_request><head><securityContext><account>[account]</account><key>[my account key]</key></securityContext></head><body><username>[my user name]</username></body></serv_request>";
NameValueCollection nvc = new NameValueCollection();
nvc.Add("xml", Server.UrlEncode(xmlrequest));
WebClient client = new WebClient();
byte[] byteresponse = client.UploadValues(url, nvc);
string xmlresponse = client.Encoding.GetString(byteresponse);
我收到了错误的回复。在文档的顶层无效。
编辑..添加提供给我的 API 手册中的说明..
string url = " http://[domain_name]/_gateway/api/[filename].asp";
// formulate the XML request here
string xmlrequest = "<serv_request>...</serv_request>";
NameValueCollection nvc = new NameValueCollection();
nvc.Add("xml", Server.UrlEncode(xmlrequest));
WebClient client = new WebClient();
byte[] byteresponse = client.UploadValues(url, nvc);
string xmlresponse = client.Encoding.GetString(byteresponse);
【问题讨论】:
-
以xml标签开始字符串?
<?xml version="1.0" encoding="UTF-8" ?> -
感谢您的回复,尝试此操作时... string xmlrequest = "
" 我遇到了同样的错误。training [我的密钥代码] [我的用户名] -
您是否尝试过在开头的
<serv_request>标记中包含XML 命名空间属性?类似<serv_request xmlns="{YourXMLNamepsace}"> -
是的,我刚刚尝试了该解决方案并得到了相同的响应。以下是我请求的服务的 API 手册中的海峡...... string url = " http://[domain_name]/_gateway/api/[filename].asp"; // 在这里制定 XML 请求 string xmlrequest = "
... "; NameValueCollection nvc = new NameValueCollection(); nvc.Add("xml", Server.UrlEncode(xmlrequest)); WebClient 客户端 = 新 WebClient(); byte[] byteresponse = client.UploadValues(url, nvc);字符串 xmlresponse = client.Encoding.GetString(byteresponse); -
如果您与网络服务通信或制作网络服务,我建议您查看ServiceStack
标签: c# xml namevaluecollection