我需要写发送一个HTTP请求,然后发送一个XML文件,然后获得对方返回的XML文件.如何做到啊? xml==txttxt==stringstring==byte []模拟请求 发送byte []也就是发送了xml请求之后 downloaddata返回byte []byte [] ==stringstring==txttxt==xmlover 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你就Post数据过去就可以了,数据内容以xml格式#region POST提交参数 /// <summary> /// POST提交参数 /// </summary> /// <param name="PostUrl">POST的地址,需要传送的地址</param> /// <param name="Parameters">POST提交参数,例如“client_id=2866517568&client_secret=9c”和get的链接类似</param> /// <returns></returns> public static string Post(string PostUrl, string Parameters) { string content = string.Empty; try { //转换为字节数组 byte[] bytesRequestData = Encoding.UTF8.GetBytes(Parameters); //path不是登录界面,是登录界面向服务器提交数据的界面 HttpWebRequest myReq = (HttpWebRequest)HttpWebRequest.Create(PostUrl); myReq.Method = "post"; myReq.ContentType = "application/x-www-form-urlencoded"; //填充POST数据 myReq.ContentLength = bytesRequestData.Length; Stream requestStream = myReq.GetRequestStream(); requestStream.Write(bytesRequestData, 0, bytesRequestData.Length); requestStream.Close(); //发送POST数据请求服务器 HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse(); //获取服务器返回信息 Stream myStream = HttpWResp.GetResponseStream(); StreamReader reader = new StreamReader(myStream, Encoding.UTF8); content = reader.ReadToEnd(); reader.Close(); HttpWResp.Close(); } catch (Exception ex) { content = ex.ToString(); } return content; } #endregion 接收Stream s = HttpContext.Current.Request.InputStream; byte[] b = new byte[s.Length]; s.Read(b, 0, (int)s.Length); postStr = Encoding.UTF8.GetString(b); if (!string.IsNullOrEmpty(postStr)) { //你要的操作 } 说得直白点就是把xml的文本(字符串)形式post到对方指定的页面上,然后将结果采集回来 xml写在post提交参数那里么?变成字符串格式不/xml文 就比如我要吧这个xml加进去怎么办<?xml version="1.0" encoding="gb2312"?><AutoUpdater> <description>Application autoUpdate</description> <Updater> <Url>http://192.168.0.103</Url> <LastUpdateTime>2005-09-05</LastUpdateTime> </Updater> <Application applicationId="ItemSoft"> <EntryPoint>ItemSoft.exe</EntryPoint> <Location>.</Location> <Version>1.0.0.0</Version> </Application> <Files> <File Ver="1.0.0.0" Name="ItemSoft.exe" /> <File Ver="1.0.0.0" Name="Reports\test.txt"/> <File Ver="1.0.0.0" Name="Interop.grproLib.dll"/> <File Ver="1.0.0.0" Name="Reports\test.grf"/> </Files></AutoUpdater>这块真的是一点都不懂,谢谢大神了 你提交过去,对方再返回给你就好了呀跟Ajax查询后处理的原理类似 WinForm中的CheckedListBox禁用某项 看谁能帮我解释一下这段代码 圆角Button FreeCommunication Ver 2.8 已经出炉,请大家捧场,多谢! 菜鸟新手求问各位一个问题,百思不得其解 ToString()后为何将Double类型的值四舍五入了? C#分析图片 在线等呢亲.... 国庆节到了,贴段发送e-mail程序与大家分享 --free(附带程序使用说明书) (在线急等)做一个类似与WinZip的程序,能实现文件打包成自解压文件,怎么实现???? 请问如何使用C#调用一个外部程序? C#.net连接sybase数据库 关于Dev版本的问题
/// <summary>
/// POST提交参数
/// </summary>
/// <param name="PostUrl">POST的地址,需要传送的地址</param>
/// <param name="Parameters">POST提交参数,例如“client_id=2866517568&client_secret=9c”和get的链接类似</param>
/// <returns></returns>
public static string Post(string PostUrl, string Parameters)
{
string content = string.Empty;
try
{
//转换为字节数组
byte[] bytesRequestData = Encoding.UTF8.GetBytes(Parameters);
//path不是登录界面,是登录界面向服务器提交数据的界面
HttpWebRequest myReq = (HttpWebRequest)HttpWebRequest.Create(PostUrl);
myReq.Method = "post";
myReq.ContentType = "application/x-www-form-urlencoded";
//填充POST数据
myReq.ContentLength = bytesRequestData.Length;
Stream requestStream = myReq.GetRequestStream();
requestStream.Write(bytesRequestData, 0, bytesRequestData.Length);
requestStream.Close();
//发送POST数据请求服务器
HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse();
//获取服务器返回信息
Stream myStream = HttpWResp.GetResponseStream();
StreamReader reader = new StreamReader(myStream, Encoding.UTF8);
content = reader.ReadToEnd();
reader.Close();
HttpWResp.Close();
}
catch (Exception ex)
{
content = ex.ToString();
}
return content;
}
#endregion
Stream s = HttpContext.Current.Request.InputStream;
byte[] b = new byte[s.Length];
s.Read(b, 0, (int)s.Length);
postStr = Encoding.UTF8.GetString(b);
if (!string.IsNullOrEmpty(postStr))
{
//你要的操作
}
就比如我要吧这个xml加进去怎么办
<?xml version="1.0" encoding="gb2312"?>
<AutoUpdater>
<description>Application autoUpdate</description>
<Updater>
<Url>http://192.168.0.103</Url>
<LastUpdateTime>2005-09-05</LastUpdateTime>
</Updater>
<Application applicationId="ItemSoft">
<EntryPoint>ItemSoft.exe</EntryPoint>
<Location>.</Location>
<Version>1.0.0.0</Version>
</Application>
<Files>
<File Ver="1.0.0.0" Name="ItemSoft.exe" />
<File Ver="1.0.0.0" Name="Reports\test.txt"/>
<File Ver="1.0.0.0" Name="Interop.grproLib.dll"/>
<File Ver="1.0.0.0" Name="Reports\test.grf"/>
</Files>
</AutoUpdater>
这块真的是一点都不懂,谢谢大神了
跟Ajax查询后处理的原理类似