我正尝试在另一个端口上的同一台机器上创建对WEB API的调用。它工作正常,并发回字符串和命中.NET断点,但参数永远不会被传递..(它为空)..是否有遗漏的经典ASP代码中传递该字符串? (DataToSend)如何使用参数将传统ASP中的HTTP POST发送到WEB API?
我的调用代码:
<%
Response.Buffer = True
Dim xml
' Set xml = Server.CreateObject("Microsoft.XMLHTTP")
Set xml = server.Createobject("MSXML2.XMLHTTP")
DataToSend="<?xml version=""1.0"" encoding=""UTF-8""?><codes sku=""123123"" num-codes=""234234"" />"
xml.Open "POST", _
"http://localhost:1303/api/RegistrationCode", _
False
xml.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xml.setRequestHeader "X-VitalSource-API-Key", "xxx"
xml.Send DataToSend
'Display the HTML both as HTML and as text
Response.Write "<h1>The HTML text</h1><xmp>"
Response.Write xml.responseText
Response.Write "</xmp><p><hr><p><h1>The HTML Output</h1>"
Response.Write xml.responseText
Set xml = Nothing
%>
WEB API代码:
public class RegistrationCodeController : ApiController
{
string testXmlString = "<SomeValue>6</SomeValue>";
public string Post([FromBody]string value)
{
return testXmlString;
}
}
谢谢皮特。在这里大量帮助我(诅咒你遗留的ASP代码)! –