aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectPoster.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectPoster.cs')
-rw-r--r--OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectPoster.cs46
1 files changed, 29 insertions, 17 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectPoster.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectPoster.cs
index b754c36..71e5b69 100644
--- a/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectPoster.cs
+++ b/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectPoster.cs
@@ -52,30 +52,42 @@ namespace OpenSim.Framework.Servers.HttpServer
52 52
53 WebRequest request = WebRequest.Create(requestUrl); 53 WebRequest request = WebRequest.Create(requestUrl);
54 request.Method = verb; 54 request.Method = verb;
55 request.ContentType = "text/xml";
56 55
57 MemoryStream buffer = new MemoryStream(); 56 if (verb == "POST")
57 {
58 request.ContentType = "text/xml";
58 59
59 XmlWriterSettings settings = new XmlWriterSettings(); 60 MemoryStream buffer = new MemoryStream();
60 settings.Encoding = Encoding.UTF8;
61 61
62 using (XmlWriter writer = XmlWriter.Create(buffer, settings)) 62 XmlWriterSettings settings = new XmlWriterSettings();
63 { 63 settings.Encoding = Encoding.UTF8;
64 XmlSerializer serializer = new XmlSerializer(type); 64
65 serializer.Serialize(writer, obj); 65 using (XmlWriter writer = XmlWriter.Create(buffer, settings))
66 writer.Flush(); 66 {
67 } 67 XmlSerializer serializer = new XmlSerializer(type);
68 serializer.Serialize(writer, obj);
69 writer.Flush();
70 }
68 71
69 int length = (int) buffer.Length; 72 int length = (int) buffer.Length;
70 request.ContentLength = length; 73 request.ContentLength = length;
74
75 Stream requestStream = request.GetRequestStream();
76 requestStream.Write(buffer.ToArray(), 0, length);
77 }
71 78
72 Stream requestStream = request.GetRequestStream();
73 requestStream.Write(buffer.ToArray(), 0, length);
74 TResponse deserial = default(TResponse); 79 TResponse deserial = default(TResponse);
75 using (WebResponse resp = request.GetResponse()) 80 try
81 {
82 using (WebResponse resp = request.GetResponse())
83 {
84 XmlSerializer deserializer = new XmlSerializer(typeof (TResponse));
85 deserial = (TResponse) deserializer.Deserialize(resp.GetResponseStream());
86 }
87 }
88 catch (System.InvalidOperationException)
76 { 89 {
77 XmlSerializer deserializer = new XmlSerializer(typeof (TResponse)); 90 // This is what happens when there is invalid XML
78 deserial = (TResponse) deserializer.Deserialize(resp.GetResponseStream());
79 } 91 }
80 return deserial; 92 return deserial;
81 } 93 }