aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/ConsoleClient/Requester.cs
diff options
context:
space:
mode:
authorMelanie2009-08-17 08:45:20 +0100
committerMelanie2009-08-17 08:45:20 +0100
commitcef16bec6dabc90fdccf82f755d24683d834208b (patch)
tree3265dbc64721f17eef82b06c7e16a7b4c6e0f657 /OpenSim/ConsoleClient/Requester.cs
parentMerge branch 'master' of ssh://melanie@opensimulator.org/var/git/opensim (diff)
downloadopensim-SC_OLD-cef16bec6dabc90fdccf82f755d24683d834208b.zip
opensim-SC_OLD-cef16bec6dabc90fdccf82f755d24683d834208b.tar.gz
opensim-SC_OLD-cef16bec6dabc90fdccf82f755d24683d834208b.tar.bz2
opensim-SC_OLD-cef16bec6dabc90fdccf82f755d24683d834208b.tar.xz
Add the OpenSim.ConsoleClient app.
Usage: OpenSim.ConsoleClient -h <host> -p <port> -u <user> -P <pass> host defaults to localhost, port defaults to 8003.
Diffstat (limited to 'OpenSim/ConsoleClient/Requester.cs')
-rw-r--r--OpenSim/ConsoleClient/Requester.cs86
1 files changed, 86 insertions, 0 deletions
diff --git a/OpenSim/ConsoleClient/Requester.cs b/OpenSim/ConsoleClient/Requester.cs
new file mode 100644
index 0000000..af7860d
--- /dev/null
+++ b/OpenSim/ConsoleClient/Requester.cs
@@ -0,0 +1,86 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.IO;
30using System.Net;
31using System.Reflection;
32using System.Text;
33using System.Xml;
34using System.Xml.Serialization;
35using log4net;
36
37namespace OpenSim.ConsoleClient
38{
39 public delegate void ReplyDelegate(string requestUrl, string requestData, string replyData);
40
41 public class Requester
42 {
43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44
45 public static void MakeRequest(string requestUrl, string data,
46 ReplyDelegate action)
47 {
48 WebRequest request = WebRequest.Create(requestUrl);
49 WebResponse response = null;
50
51 request.Method = "POST";
52
53 request.ContentType = "application/x-www-form-urlencoded";
54
55 byte[] buffer = new System.Text.ASCIIEncoding().GetBytes(data);
56 int length = (int) buffer.Length;
57 request.ContentLength = length;
58
59 request.BeginGetRequestStream(delegate(IAsyncResult res)
60 {
61 Stream requestStream = request.EndGetRequestStream(res);
62
63 requestStream.Write(buffer, 0, length);
64
65 request.BeginGetResponse(delegate(IAsyncResult ar)
66 {
67 string reply = String.Empty;
68
69 response = request.EndGetResponse(ar);
70
71 try
72 {
73 StreamReader r = new StreamReader(response.GetResponseStream());
74 reply = r.ReadToEnd();
75
76 }
77 catch (System.InvalidOperationException)
78 {
79 }
80
81 action(requestUrl, data, reply);
82 }, null);
83 }, null);
84 }
85 }
86}