testing different rest post method/class for Grid asset client. (possible that I haven't set the post url correctly)

This commit is contained in:
MW
2007-11-03 14:04:59 +00:00
parent f8e0cf0f1d
commit 91c2c3c096
2 changed files with 60 additions and 9 deletions

View File

@@ -0,0 +1,49 @@
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace OpenSim.Framework.Servers
{
public class RestObjectPoster
{
public static void BeginPostObject<TRequest>(string requestUrl, TRequest obj)
{
Type type = typeof(TRequest);
WebRequest request = WebRequest.Create(requestUrl);
request.Method = "POST";
request.ContentType = "text/xml";
MemoryStream buffer = new MemoryStream();
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = Encoding.UTF8;
using (XmlWriter writer = XmlWriter.Create(buffer, settings))
{
XmlSerializer serializer = new XmlSerializer(type);
serializer.Serialize(writer, obj);
writer.Flush();
}
int length = (int)buffer.Length;
request.ContentLength = length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(buffer.ToArray(), 0, length);
IAsyncResult result = request.BeginGetResponse(AsyncCallback, request);
}
private static void AsyncCallback(IAsyncResult result)
{
WebRequest request = (WebRequest)result.AsyncState;
using (WebResponse resp = request.EndGetResponse(result))
{
}
}
}
}