C#.NET中的Microsoft.XMLHTTP [英] Microsoft.XMLHTTP in C#.NET

查看:280
本文介绍了C#.NET中的Microsoft.XMLHTTP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个将ASP经典代码转换为C#的项目,然后我进入了代码的这一部分...

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-www-form-urlencoded"
    oHTTP.send                  "IN=" & Server.UrlEncode(sRequest)

    sResponse = oHTTP.responseText
    sendRequest = sResponse
    End Function

该函数基本上通过HTTP发送XML数据,并且使用Microsoft.XMLHTTP对象.现在,.NET中此对象(Microsoft.XMLHTTP)的等效项是什么,因为我不想使用此旧式经典DLL ...

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...

谢谢...

推荐答案

在.NET中,最简单的实现是:

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);
}

我在这里使用C#,但它也适用于VB.

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

这篇关于C#.NET中的Microsoft.XMLHTTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆