我正嘗試在另一個端口上的同一臺機器上創建對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代碼)! –