I am using a proxy service to allow my client side javascript to talk to a service on another domain
The proxy is a simple ashx file with simply gets the request and forwards it onto the service on the other domain :
using (var sr = new System.IO.StreamReader(context.Request.InputStream))
{
requestData = sr.ReadToEnd();
}
string data = HttpUtility.UrlDecode(requestData);
using (var client = new WebClient())
{
client.BaseAddress = serviceUrl;
client.Headers.Add("Content-Type", "application/json");
response = client.UploadString(new Uri(webserviceUrl), data);
}
The client javascript calling this proxy looks like this
function TestMethod() {
$.ajax({
type: "POST",
url: "/custommodules/configuratorproxyservice.ashx?m=TestMethod",
contentType: "application/json; charset=utf-8",
data: JSON.parse('{"testObj":{"Name":"jo","Ref":"jones","LastModified":"\/Date(-62135596800000+0000)\/"}}'),
dataType: "json",
success: AjaxSucceeded,
error: AjaxFailed
});
function AjaxSucceeded(result) {
alert(result);
}
function AjaxFailed(result) {
alert(result.status + ' - ' + result.statusText);
}
}
This works fine until I have to pass a date. At which point I get a Bad Request error when the proxy tries to call the service.
That is to say, if I remove the ,"LastModified":"\/Date(-62135596800000+0000)\/"
from the json data then the call succeed. Add it back in and it fails.
If I make the call from the same domain it is fine, it's only when it goes via the proxy that it fails.
I did have this working at one point but have now lost it.
Have tried using JSON.Parse on the object before sending. and JSON.Stringify, but no joy
anyone got any ideas what I am missing?
have also tried the customised parser methods mentioned in this article http://www.west-wind.com/Weblog/posts/896411.aspx
Any ideas?