Modified:
/src/Jayrock.Sandbox/JsonRpcClient.cs
=======================================
--- /src/Jayrock.Sandbox/JsonRpcClient.cs Mon Jul 4 09:33:32 2011
+++ /src/Jayrock.Sandbox/JsonRpcClient.cs Wed Aug 31 14:24:05 2011
@@ -26,6 +26,7 @@
using System;
using System.Collections;
+ using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Net;
@@ -39,7 +40,37 @@
public class JsonRpcClient : HttpWebClientProtocol
{
private int _id;
+ private string[] _jsonRpcMediaTypes;
+
private static readonly object[] _zeroArgs = new object[0];
+
+ public string[] JsonRpcMediaTypes
+ {
+ get
+ {
+ if (_jsonRpcMediaTypes == null)
+ {
+ return new string[]
+ {
+ "application/json",
+ "application/json-rpc",
+ "application/jsonrequest"
+ };
+ }
+
+ return (string[]) _jsonRpcMediaTypes.Clone();
+ }
+
+ set
+ {
+ if (value == null)
+ throw new ArgumentNullException("value");
+
+ _jsonRpcMediaTypes = value.Length > 0
+ ? (string[]) value.Clone()
+ : value;
+ }
+ }
public object Invoke(string method)
{
@@ -92,9 +123,16 @@
WebRequest request = GetWebRequest(new Uri(Url));
request.Method = "POST";
-
+
+ Encoding requestEncoding = RequestEncoding;
+ if (requestEncoding == null)
+ requestEncoding = Encoding.UTF8;
+
+ request.ContentType = RequestMediaType
+ + "; charset=" +
requestEncoding.HeaderName;
+
using (Stream stream = request.GetRequestStream())
- using (StreamWriter writer = new StreamWriter(stream,
Encoding.UTF8))
+ using (StreamWriter writer = new StreamWriter(stream,
requestEncoding))
{
JsonObject call = new JsonObject();
call["id"] = ++_id;
@@ -108,6 +146,17 @@
using (StreamReader reader = new StreamReader(stream,
Encoding.UTF8))
return OnResponse(JsonText.CreateReader(reader),
returnType);
}
+
+ private string RequestMediaType
+ {
+ get
+ {
+ string[] types = _jsonRpcMediaTypes;
+ string type = types != null && types.Length > 0 ?
types[0] : null;
+ type = Mask.NullString(type).Trim();
+ return Mask.EmptyString(type, "application/json");
+ }
+ }
public object OnResponse(JsonReader reader, Type returnType)
{