通过HTTP POST到IP发送XML:港口 [英] Send XML via HTTP Post to IP:Port

查看:156
本文介绍了通过HTTP POST到IP发送XML:港口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定,所以出发了,我没有使用任何类型的Web服务。现在我不知道一大堆有关应用程序接受其他比它接收它的XML。大的帮助那里,我知道了。我没有写接收应用程序,但我公司不具备测试XML传输阶段的任何有用的方法。



基本上,我想送一个XML文档这样的...

 < H2HXmlRequest类=MyClass的> 
<呼叫和GT;
<&来电显示GT;< /&来电显示GT;
<工期和GT; 0℃; /时间>
< /呼叫>
<终端>
< CancelDate>< / CancelDate>
< ClerkLoginTime>< / ClerkLoginTime>
< /终端>
<&交易GT;
< AcceptedCurrency>< / AcceptedCurrency>
<&ACCOUNTID GT; 6208700003< / ACCOUNTID>
< /交易>
< / H2HXmlRequest>



...来,我真的不知道了一大堆有关应用程序。这是没有什么花哨和适当的帮助下,我也许可以找到更多信息。但是我希望做的是拿出一些C#窗体应用程序,可以采取上面的要求,发送超过使用IP和端口,并希望看到的东西发生。


< DIV CLASS =h2_lin>解决方案

进行简单的Web请求的推荐方法是使用WebClient的对象。



下面的代码片段

  //假设你的XML字符串是从GetXmlString()
串XML = GetXmlString()返回;


//假设端口8080
字符串URL =新UriBuilder(HTTP,www.example.com,8080)的ToString();


//创建一个使用客户端对象
(System.Net.WebClient客户端=新System.Net.WebClient()){
//执行HTTP POST
client.UploadString(URL,XML);

}


Ok so to start off, I'm not using any sort of web service. Right now I don't know a whole lot about the application receiving the XML other than it receives it. Big help there I know. I didn't write the receiving application but my company doesn't have any useful ways of testing the XML transmission phase.

I basically want to send an XML document like this...

<H2HXmlRequest class="myClass">
<Call>
    <CallerID></CallerID>
    <Duration>0</Duration>
</Call>
<Terminal>
    <CancelDate></CancelDate>
    <ClerkLoginTime></ClerkLoginTime>
</Terminal>
<Transaction>
    <AcceptedCurrency></AcceptedCurrency>
    <AccountId>6208700003</AccountId>
</Transaction>
</H2HXmlRequest>

...to the application that I don't really know a whole lot about. It's nothing fancy and with the proper help I could probably find out more info. But what I am looking to do is to come up with some kind of C# Forms app that can take that request above, send it on over using an IP and port, and hopefully see something happen.

解决方案

The recommended way to make simple web requests is to use the WebClient object.

Here's a code snippet:

// assume your XML string is returned from GetXmlString()
string xml = GetXmlString();


// assume port 8080
string url = new UriBuilder("http","www.example.com",8080).ToString();     


// create a client object
using(System.Net.WebClient client = new System.Net.WebClient()) {
    // performs an HTTP POST
    client.UploadString(url, xml);  

}

这篇关于通过HTTP POST到IP发送XML:港口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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