diff options
Some refactoring , mainly on Inventory code.
Diffstat (limited to 'OpenSim/Framework/Servers/SynchronousRestObjectPoster.cs')
-rw-r--r-- | OpenSim/Framework/Servers/SynchronousRestObjectPoster.cs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/OpenSim/Framework/Servers/SynchronousRestObjectPoster.cs b/OpenSim/Framework/Servers/SynchronousRestObjectPoster.cs new file mode 100644 index 0000000..dde4c02 --- /dev/null +++ b/OpenSim/Framework/Servers/SynchronousRestObjectPoster.cs | |||
@@ -0,0 +1,48 @@ | |||
1 | using System; | ||
2 | using System.IO; | ||
3 | using System.Net; | ||
4 | using System.Text; | ||
5 | using System.Xml; | ||
6 | using System.Xml.Serialization; | ||
7 | |||
8 | namespace OpenSim.Framework.Servers | ||
9 | { | ||
10 | public class SynchronousRestObjectPoster | ||
11 | { | ||
12 | public static TResponse BeginPostObject<TRequest, TResponse>(string requestUrl, TRequest obj) | ||
13 | { | ||
14 | Type type = typeof(TRequest); | ||
15 | |||
16 | WebRequest request = WebRequest.Create(requestUrl); | ||
17 | request.Method = "POST"; | ||
18 | request.ContentType = "text/xml"; | ||
19 | |||
20 | MemoryStream buffer = new MemoryStream(); | ||
21 | |||
22 | XmlWriterSettings settings = new XmlWriterSettings(); | ||
23 | settings.Encoding = Encoding.UTF8; | ||
24 | |||
25 | using (XmlWriter writer = XmlWriter.Create(buffer, settings)) | ||
26 | { | ||
27 | XmlSerializer serializer = new XmlSerializer(type); | ||
28 | serializer.Serialize(writer, obj); | ||
29 | writer.Flush(); | ||
30 | } | ||
31 | |||
32 | int length = (int)buffer.Length; | ||
33 | request.ContentLength = length; | ||
34 | |||
35 | Stream requestStream = request.GetRequestStream(); | ||
36 | requestStream.Write(buffer.ToArray(), 0, length); | ||
37 | TResponse deserial = default(TResponse); | ||
38 | using (WebResponse resp = request.GetResponse()) | ||
39 | { | ||
40 | |||
41 | XmlSerializer deserializer = new XmlSerializer(typeof(TResponse)); | ||
42 | deserial = (TResponse)deserializer.Deserialize(resp.GetResponseStream()); | ||
43 | } | ||
44 | return deserial; | ||
45 | } | ||
46 | |||
47 | } | ||
48 | } | ||