C#.NET中的Microsoft.XMLHTTP
我目前有一个将asp经典代码转换为C#的项目,然后我进入了代码的这一部分C#.NET中的Microsoft.XMLHTTP,c#,xml,asp-classic,C#,Xml,Asp Classic,我目前有一个将asp经典代码转换为C#的项目,然后我进入了代码的这一部分 Function sendRequest(sRequest) //sRequest is XML data Dim sResponse Set oHTTP = Server.CreateObject("Microsoft.XMLHTTP") oHTTP.open HTTP_POST, WDL_URL_PREFIX, false oHTTP.set
Function sendRequest(sRequest) //sRequest is XML data
Dim sResponse
Set oHTTP = Server.CreateObject("Microsoft.XMLHTTP")
oHTTP.open HTTP_POST, WDL_URL_PREFIX, false
oHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
oHTTP.send "IN=" & Server.UrlEncode(sRequest)
sResponse = oHTTP.responseText
sendRequest = sResponse
End Function
该函数基本上通过HTTP发送XML数据,并使用Microsoft.XMLHTTP对象。现在,这个对象(Microsoft.XMLHTTP)在.NET中的等价物是什么,因为我不想使用这个遗留的经典DLL
谢谢…尝试查看
System.Net.WebRequest
:
在.NET中,最简单的实现是:
string url = ..., request = ...;
using (var client = new WebClient())
{
var response = client.UploadValues(url, new NameValueCollection {
{"IN",request}
});
var text = client.Encoding.GetString(response);
}
我在这里使用C#,但它也适用于VB。谢谢,但我在新的NameValueCollection{{“in”,request}//中得到错误重载+1,您是对的,对于这个用例,WebClient比WebRequest更合适。(删除了我的答案。)