I am sending my JSON string to this url http://myipaddress/WindowsApp/Registration?data=
I am using the following code which is as follows :
internal static async Task<String> getHttpResponse(HttpWebRequest request,string postData)
{
String received = null;
byte[] requestBody = Encoding.UTF8.GetBytes(postData);
using(var postStream=await request.GetRequestStreamAsync())
{
await postStream.WriteAsync(requestBody, 0, requestBody.Length);
}
try
{
var response = (HttpWebResponse)await request.GetResponseAsync();
if(response != null)
{
var reader = new StreamReader(response.GetResponseStream());
received = await reader.ReadToEndAsync();
}
}
catch(WebException ae)
{
var reader = new StreamReader(ae.Response.GetResponseStream());
string responseString = reader.ToString();
Debug.WriteLine("################ EXCEPTIONAL RESPONSE STRING ################");
Debug.WriteLine(responseString);
return responseString;
}
return received;
}
and I am calling this method when I click on one of my buttons in XAML as follows :
HttpWebRequest request = HttpWebRequest.Create(Classes.Constants.SERVER_URL) as HttpWebRequest;
request.Method = "POST";
request.ContentType = "application/json";
postData = JsonConvert.SerializeObject(user);
string receivedString = await getHttpResponse(request, postData);
Debug.WriteLine("############# RECEIVED STRING #############");
Debug.WriteLine(receivedString);
So, the problem I am facing is that I am unable to get the string on the server.
Note : I am able to get the json string when my server implements its method with a url : http://myipaddress/WindowsApp/Registration
(without parameter "?data=") and also sends me response string. But fails when the term "?data="
is implemented and used in the server url.
So what am I going wrong in my code? Please help.