<?xml version="1.0" encoding="ISO-8859-1" ?> 
<root>
  <background>
    <SourceAddress>200.20.8.10</SourceAddress> 
    <SourcePort>1234</SourcePort> 
    <PID>1345</PID> 
  </background>
</root>
用C#如何实现向远程服务器提交上面的数据?
最好提供示例!
谢谢了!

解决方案 »

  1.   

    写一个XML文件不就行了
    不过得先给权限
      

  2.   

    楼主是想怎么发送?搞不清楚,首先肯定要先写一个解析xml的类,把结果记住,然后根据解析后的数据用socket发送不就搞定了吗?
      

  3.   

    感谢各位的支持!
    我这个不需要服务器授权,通过HTTP发送,不要用xml文件保存!
    有谁知道,给个示例啊!!
      

  4.   

    用System.Xml.XmlDocument,具体方法看帮助
      

  5.   

    使用DATASET传送吧,使用ReadXml()方法把上面读入DATASET.
      

  6.   

    做法:
    winform:string postData = "a=" + textBox1.Text;
    Encoding encoding = Encoding.UTF8;
    byte[] data = encoding.GetBytes(postData);
    System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create("http://localhost:8801/A.aspx");
    req.Method = "POST";
    req.ContentType = "application/x-www-form-urlencoded";
    req.ContentLength = data.Length;
    System.IO.Stream newStream = req.GetRequestStream();
    // 发送数据
    newStream.Write(data, 0, data.Length);      
    System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)req.GetResponse();
    MessageBox.Show(res.StatusDescription.ToString());
    newStream.Close();a.aspx
    ============
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="A.aspx.cs" Inherits="A" ValidateRequest="false" %>a.aspx.cs
    ============
     protected void Page_Load( object sender, EventArgs e )
      {
        System.IO.StreamWriter sw = new System.IO.StreamWriter(Server.MapPath("a.txt"),true,System.Text.Encoding.UTF8);
        sw.Write(Request.Form["a"]);
        sw.Close();
      }
      

  7.   

    也可以 
    string postData = textBox1.Text;
    Encoding encoding = Encoding.UTF8;
    byte[] data = encoding.GetBytes(postData);
    System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create("http://localhost:8801/A.aspx");
    req.Method = "POST";
    req.ContentType = "application/x-www-form-urlencoded";
    req.ContentLength = data.Length;
    System.IO.Stream newStream = req.GetRequestStream();
    // 发送数据
    newStream.Write(data, 0, data.Length);      
    System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)req.GetResponse();
    MessageBox.Show(res.StatusDescription.ToString());
    newStream.Close();
    aspx.cs:protected void Page_Load( object sender, EventArgs e )
      {
        System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
        doc.Load(Request.InputStream);
       doc.Save(Server.MapPath("a.xml"));
      }
      

  8.   

    因为我很菜,请net_lover把上面的代码解释一下啊,最好把我上面要提交的数据结合起来一起解释,让我更明白。
    感谢了!!!
      

  9.   

    // 这个里面的内容就是你的xml内容。
    string postData = textBox1.Text;
    //  这一段是将输入的xml内容转化为byte数组,
    Encoding encoding = Encoding.UTF8;
    byte[] data = encoding.GetBytes(postData);
    // 这一段使用webrequest发送http消息,模拟浏览器提交的效果
    System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create("http://localhost:8801/A.aspx");
    // 设置http的方法是post,post/get二种方法
    req.Method = "POST";
    // 模拟form的类型,一般来说用这种类型的form
    req.ContentType = "application/x-www-form-urlencoded";
    // 数据长度,http要求
    req.ContentLength = data.Length;
    // 利用二进制流发送数据
    System.IO.Stream newStream = req.GetRequestStream();
    // 发送数据
    newStream.Write(data, 0, data.Length);      
    // 得到http的返回结果
    System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)req.GetResponse();
    MessageBox.Show(res.StatusDescription.ToString());
    // 关闭流
    newStream.Close();
      

  10.   

    生成xml,你可以直接用string = "<?xml version="1.0" encoding="ISO-8859-1" ?>\n <root>\n  <background>\n",这个办法最简单