一个关于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();
}