aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/SynchronousRestObjectPoster.cs
diff options
context:
space:
mode:
authorMW2007-12-02 13:59:15 +0000
committerMW2007-12-02 13:59:15 +0000
commit80609c2b1572d9b946675db486fc46e327171cfa (patch)
tree85a623c1a75255d74883c3f9ba11e5f66a053a18 /OpenSim/Framework/Servers/SynchronousRestObjectPoster.cs
parentNew Inventory folder should now be stored to the inventory server/database. T... (diff)
downloadopensim-SC_OLD-80609c2b1572d9b946675db486fc46e327171cfa.zip
opensim-SC_OLD-80609c2b1572d9b946675db486fc46e327171cfa.tar.gz
opensim-SC_OLD-80609c2b1572d9b946675db486fc46e327171cfa.tar.bz2
opensim-SC_OLD-80609c2b1572d9b946675db486fc46e327171cfa.tar.xz
Some refactoring , mainly on Inventory code.
Diffstat (limited to 'OpenSim/Framework/Servers/SynchronousRestObjectPoster.cs')
-rw-r--r--OpenSim/Framework/Servers/SynchronousRestObjectPoster.cs48
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 @@
1using System;
2using System.IO;
3using System.Net;
4using System.Text;
5using System.Xml;
6using System.Xml.Serialization;
7
8namespace 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}