一个关于C#利用HTTP传输xml字符串的有关问题
一个关于C#,利用HTTP传输xml字符串的问题
刚接触项目,有个问题请教下各位大侠~对方要求将解析完的xml利用http传给他,url已给,http://ip:port/nms/upload,然后我序列化的部分也做完了:
public string Serialize()
{
string strSource = "";
try
{
Snapshot = null;
XmlSerializer s = new XmlSerializer(typeof(MSG_PU_VIDEO_DEVICE_ALARM));
Stream stream = new MemoryStream();
s.Serialize(stream, this);
stream.Seek(0, SeekOrigin.Begin);
using (StreamReader reader = new StreamReader(stream))
{
strSource = reader.ReadToEnd();
}
}
catch (Exception ex)
{
throw ex;
}
return strSource;
}
public static MSG_PU_VIDEO_DEVICE_ALARM Deserialize(string xmlSource)
{
MSG_PU_VIDEO_DEVICE_ALARM obj = new MSG_PU_VIDEO_DEVICE_ALARM();
try
{
XmlSerializer x = new XmlSerializer(typeof(MSG_PU_VIDEO_DEVICE_ALARM));
Stream stream = ProtocolHelper.GetStream(xmlSource);
stream.Seek(0, SeekOrigin.Begin);
obj = (MSG_PU_VIDEO_DEVICE_ALARM)x.Deserialize(stream);
stream.Close();
}
catch (Exception ex)
{
throw ex;
}
return obj;
}
}
然后我将如何将序列化完的结果传出去呢,可以给个或者写个简单的demo呢,谢谢啦!
------解决方案--------------------
把XML保存为文本文件,再上传就好了.
------解决方案--------------------
你百度查httpwebrequst post
刚接触项目,有个问题请教下各位大侠~对方要求将解析完的xml利用http传给他,url已给,http://ip:port/nms/upload,然后我序列化的部分也做完了:
public string Serialize()
{
string strSource = "";
try
{
Snapshot = null;
XmlSerializer s = new XmlSerializer(typeof(MSG_PU_VIDEO_DEVICE_ALARM));
Stream stream = new MemoryStream();
s.Serialize(stream, this);
stream.Seek(0, SeekOrigin.Begin);
using (StreamReader reader = new StreamReader(stream))
{
strSource = reader.ReadToEnd();
}
}
catch (Exception ex)
{
throw ex;
}
return strSource;
}
public static MSG_PU_VIDEO_DEVICE_ALARM Deserialize(string xmlSource)
{
MSG_PU_VIDEO_DEVICE_ALARM obj = new MSG_PU_VIDEO_DEVICE_ALARM();
try
{
XmlSerializer x = new XmlSerializer(typeof(MSG_PU_VIDEO_DEVICE_ALARM));
Stream stream = ProtocolHelper.GetStream(xmlSource);
stream.Seek(0, SeekOrigin.Begin);
obj = (MSG_PU_VIDEO_DEVICE_ALARM)x.Deserialize(stream);
stream.Close();
}
catch (Exception ex)
{
throw ex;
}
return obj;
}
}
然后我将如何将序列化完的结果传出去呢,可以给个或者写个简单的demo呢,谢谢啦!
------解决方案--------------------
把XML保存为文本文件,再上传就好了.
------解决方案--------------------
你百度查httpwebrequst post