diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/WebUtil.cs | 78 |
1 files changed, 7 insertions, 71 deletions
diff --git a/OpenSim/Framework/WebUtil.cs b/OpenSim/Framework/WebUtil.cs index 854f310..f90df12 100644 --- a/OpenSim/Framework/WebUtil.cs +++ b/OpenSim/Framework/WebUtil.cs | |||
@@ -63,77 +63,7 @@ namespace OpenSim.Framework | |||
63 | // a "long" call for warning & debugging purposes | 63 | // a "long" call for warning & debugging purposes |
64 | public const int LongCallTime = 500; | 64 | public const int LongCallTime = 500; |
65 | 65 | ||
66 | // /// <summary> | 66 | #region JSONRequest |
67 | // /// Send LLSD to an HTTP client in application/llsd+json form | ||
68 | // /// </summary> | ||
69 | // /// <param name="response">HTTP response to send the data in</param> | ||
70 | // /// <param name="body">LLSD to send to the client</param> | ||
71 | // public static void SendJSONResponse(OSHttpResponse response, OSDMap body) | ||
72 | // { | ||
73 | // byte[] responseData = Encoding.UTF8.GetBytes(OSDParser.SerializeJsonString(body)); | ||
74 | // | ||
75 | // response.ContentEncoding = Encoding.UTF8; | ||
76 | // response.ContentLength = responseData.Length; | ||
77 | // response.ContentType = "application/llsd+json"; | ||
78 | // response.Body.Write(responseData, 0, responseData.Length); | ||
79 | // } | ||
80 | // | ||
81 | // /// <summary> | ||
82 | // /// Send LLSD to an HTTP client in application/llsd+xml form | ||
83 | // /// </summary> | ||
84 | // /// <param name="response">HTTP response to send the data in</param> | ||
85 | // /// <param name="body">LLSD to send to the client</param> | ||
86 | // public static void SendXMLResponse(OSHttpResponse response, OSDMap body) | ||
87 | // { | ||
88 | // byte[] responseData = OSDParser.SerializeLLSDXmlBytes(body); | ||
89 | // | ||
90 | // response.ContentEncoding = Encoding.UTF8; | ||
91 | // response.ContentLength = responseData.Length; | ||
92 | // response.ContentType = "application/llsd+xml"; | ||
93 | // response.Body.Write(responseData, 0, responseData.Length); | ||
94 | // } | ||
95 | |||
96 | /// <summary> | ||
97 | /// Make a GET or GET-like request to a web service that returns LLSD | ||
98 | /// or JSON data | ||
99 | /// </summary> | ||
100 | public static OSDMap ServiceRequest(string url, string httpVerb) | ||
101 | { | ||
102 | string errorMessage; | ||
103 | |||
104 | try | ||
105 | { | ||
106 | HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); | ||
107 | request.Method = httpVerb; | ||
108 | |||
109 | using (WebResponse response = request.GetResponse()) | ||
110 | { | ||
111 | using (Stream responseStream = response.GetResponseStream()) | ||
112 | { | ||
113 | try | ||
114 | { | ||
115 | string responseStr = responseStream.GetStreamString(); | ||
116 | OSD responseOSD = OSDParser.Deserialize(responseStr); | ||
117 | if (responseOSD.Type == OSDType.Map) | ||
118 | return (OSDMap)responseOSD; | ||
119 | else | ||
120 | errorMessage = "Response format was invalid."; | ||
121 | } | ||
122 | catch | ||
123 | { | ||
124 | errorMessage = "Failed to parse the response."; | ||
125 | } | ||
126 | } | ||
127 | } | ||
128 | } | ||
129 | catch (Exception ex) | ||
130 | { | ||
131 | m_log.Warn(httpVerb + " on URL " + url + " failed: " + ex.Message); | ||
132 | errorMessage = ex.Message; | ||
133 | } | ||
134 | |||
135 | return new OSDMap { { "Message", OSD.FromString("Service request failed. " + errorMessage) } }; | ||
136 | } | ||
137 | 67 | ||
138 | /// <summary> | 68 | /// <summary> |
139 | /// PUT JSON-encoded data to a web service that returns LLSD or | 69 | /// PUT JSON-encoded data to a web service that returns LLSD or |
@@ -304,6 +234,10 @@ namespace OpenSim.Framework | |||
304 | return result; | 234 | return result; |
305 | } | 235 | } |
306 | 236 | ||
237 | #endregion JSONRequest | ||
238 | |||
239 | #region FormRequest | ||
240 | |||
307 | /// <summary> | 241 | /// <summary> |
308 | /// POST URL-encoded form data to a web service that returns LLSD or | 242 | /// POST URL-encoded form data to a web service that returns LLSD or |
309 | /// JSON data | 243 | /// JSON data |
@@ -398,6 +332,8 @@ namespace OpenSim.Framework | |||
398 | result["Message"] = OSD.FromString("Service request failed: " + msg); | 332 | result["Message"] = OSD.FromString("Service request failed: " + msg); |
399 | return result; | 333 | return result; |
400 | } | 334 | } |
335 | |||
336 | #endregion FormRequest | ||
401 | 337 | ||
402 | #region Uri | 338 | #region Uri |
403 | 339 | ||