开发者

Microsoft.XMLHTTP in C#.NET

开发者 https://www.devze.com 2023-03-07 04:02 出处:网络
I currently have aproject converting asp classic codes to C#, then i came into this section of the code...

I currently have a project converting asp classic codes to C#, then i came into this section of the code...

    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-w开发者_如何学编程ww-form-urlencoded"
    oHTTP.send                  "IN=" & Server.UrlEncode(sRequest)

    sResponse = oHTTP.responseText
    sendRequest = sResponse
    End Function

The function basically sends XML data via HTTP and it uses Microsoft.XMLHTTP object. Now, what is the equivalent of this object(Microsoft.XMLHTTP) in .NET because I don't want to use this legacy classic DLL...

Thanks...


In .NET, the easiest implementation there is simply:

string url = ..., request = ...;
using (var client = new WebClient())
{
    var response = client.UploadValues(url, new NameValueCollection {
        {"IN",request}
    });
    var text = client.Encoding.GetString(response);
}

I'm using C# here, but it applies to VB too.


Try looking into System.Net.WebRequest: http://msdn.microsoft.com/en-us/library/system.net.webrequest.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消