diff --git a/OpenSim/Framework/Communications/Cache/GridAssetClient.cs b/OpenSim/Framework/Communications/Cache/GridAssetClient.cs index 64e561b37e..632f96cc4e 100644 --- a/OpenSim/Framework/Communications/Cache/GridAssetClient.cs +++ b/OpenSim/Framework/Communications/Cache/GridAssetClient.cs @@ -32,6 +32,7 @@ using System.IO; using System.Xml.Serialization; using libsecondlife; using OpenSim.Framework.Console; +using OpenSim.Framework.Servers; namespace OpenSim.Framework.Communications.Cache { @@ -103,16 +104,17 @@ namespace OpenSim.Framework.Communications.Cache { try { - MemoryStream s = new MemoryStream(); + // MemoryStream s = new MemoryStream(); - XmlSerializer xs = new XmlSerializer(typeof (AssetBase)); - xs.Serialize(s, asset); - RestClient rc = new RestClient(_assetServerUrl); - MainLog.Instance.Verbose("ASSET", "Storing {0}", rc); - rc.AddResourcePath("assets"); - rc.RequestMethod = "POST"; - rc.Request(s); - MainLog.Instance.Verbose("ASSET", "Stored {0}", rc); + // XmlSerializer xs = new XmlSerializer(typeof(AssetBase)); + // xs.Serialize(s, asset); + // RestClient rc = new RestClient(_assetServerUrl); + MainLog.Instance.Verbose("ASSET", "Storing asset"); + //rc.AddResourcePath("assets"); + // rc.RequestMethod = "POST"; + // rc.Request(s); + //MainLog.Instance.Verbose("ASSET", "Stored {0}", rc); + RestObjectPoster.BeginPostObject(_assetRequests + "/assets/", asset); } catch (Exception e) { diff --git a/OpenSim/Framework/Servers/RestObjectPoster.cs b/OpenSim/Framework/Servers/RestObjectPoster.cs new file mode 100644 index 0000000000..77660a02f8 --- /dev/null +++ b/OpenSim/Framework/Servers/RestObjectPoster.cs @@ -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(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)) + { + } + } + } +} \ No newline at end of file