Code below is working but i want to use this by httpwebrequest in my windows form application to get data.
$.getJSON("JSONHandler", {
metod: "mymethod",
param: {
id: "123",
name: "Jhon",
surname: "Tiger",
birthdate: "7.2.1949"
}
}, function (json) {
if (json.Mesaj)
return alert(json.Mesaj);
if (json.hasinfo) {
PageMethods.MyMethod(JSON.stringify(json.phoneNo));
}
else {
alert("Something wrong");
}
});
I try to code below
var httpWebRequest = (HttpWebRequest)WebRequest.Create("JSONHandler");
httpWebRequest.ContentType = "application/json; charset=utf-8";
httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string json = "{" +
" \"metod\": \"mymethod\", " +
" \"param\": { " +
" \"id\": \"123\", " +
" \"name\": \"Jhon\", " +
" \"surname\": \"Tiger\", " +
" \"birth\": \"7.2.1949\" " +
" } " +
" }";
streamWriter.Write(json);
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var responseText = streamReader.ReadToEnd();
//Now you have your response.
//or false depending on information in the response
}
But it returns nullpointer exception error from server i thing my params are wrong. What must i do?