diff options
Diffstat (limited to 'OpenSim/Framework/Servers/RestObjectPoster.cs')
-rw-r--r-- | OpenSim/Framework/Servers/RestObjectPoster.cs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/OpenSim/Framework/Servers/RestObjectPoster.cs b/OpenSim/Framework/Servers/RestObjectPoster.cs new file mode 100644 index 0000000..77660a0 --- /dev/null +++ b/OpenSim/Framework/Servers/RestObjectPoster.cs | |||
@@ -0,0 +1,49 @@ | |||
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 | |||
9 | namespace OpenSim.Framework.Servers | ||
10 | { | ||
11 | public class RestObjectPoster | ||
12 | { | ||
13 | public static void BeginPostObject<TRequest>(string requestUrl, TRequest obj) | ||
14 | { | ||
15 | Type type = typeof(TRequest); | ||
16 | |||
17 | WebRequest request = WebRequest.Create(requestUrl); | ||
18 | request.Method = "POST"; | ||
19 | request.ContentType = "text/xml"; | ||
20 | |||
21 | MemoryStream buffer = new MemoryStream(); | ||
22 | |||
23 | XmlWriterSettings settings = new XmlWriterSettings(); | ||
24 | settings.Encoding = Encoding.UTF8; | ||
25 | |||
26 | using (XmlWriter writer = XmlWriter.Create(buffer, settings)) | ||
27 | { | ||
28 | XmlSerializer serializer = new XmlSerializer(type); | ||
29 | serializer.Serialize(writer, obj); | ||
30 | writer.Flush(); | ||
31 | } | ||
32 | |||
33 | int length = (int)buffer.Length; | ||
34 | request.ContentLength = length; | ||
35 | |||
36 | Stream requestStream = request.GetRequestStream(); | ||
37 | requestStream.Write(buffer.ToArray(), 0, length); | ||
38 | IAsyncResult result = request.BeginGetResponse(AsyncCallback, request); | ||
39 | } | ||
40 | |||
41 | private static void AsyncCallback(IAsyncResult result) | ||
42 | { | ||
43 | WebRequest request = (WebRequest)result.AsyncState; | ||
44 | using (WebResponse resp = request.EndGetResponse(result)) | ||
45 | { | ||
46 | } | ||
47 | } | ||
48 | } | ||
49 | } \ No newline at end of file | ||