Problem with Json Date format when calling cross-domain proxy
Posted
by Christo Fur
on Stack Overflow
See other posts from Stack Overflow
or by Christo Fur
Published on 2010-04-27T10:41:11Z
Indexed on
2010/04/27
10:43 UTC
Read the original article
Hit count: 631
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
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
© Stack Overflow or respective owner