Click here to Skip to main content
15,936,395 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When i try to send the JSON data to server it is throwing exception
is there change setting in Windows phone 8

here my code sample :-
C#
private void PostJsonRequest() 
{ 
   //Please replace your webservice url here
   string AuthServiceUri = "http://test.postjson.com/Login?"; 
   HttpWebRequest spAuthReq = HttpWebRequest.Create(AuthServiceUri) as HttpWebRequest; 
   spAuthReq.ContentType = "application/json"; 
   spAuthReq.Method = "POST"; 
   spAuthReq.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), spAuthReq); 
} 
 
void GetRequestStreamCallback(IAsyncResult callbackResult) 
{ 
   HttpWebRequest myRequest = (HttpWebRequest)callbackResult.AsyncState; 
   Stream postStream = myRequest.EndGetRequestStream(callbackResult); 
   string postData = "{'userid': '2','username':'subbu'}"; 
   byte[] byteArray = Encoding.UTF8.GetBytes(postData); 
   postStream.Write(byteArray, 0, byteArray.Length); 
   postStream.Close(); 
   myRequest.BeginGetResponse(new AsyncCallback(GetResponsetStreamCallback), myRequest); 
} 
 
void GetResponsetStreamCallback(IAsyncResult callbackResult) 
{ 
   try 
   { 
      HttpWebRequest request = (HttpWebRequest)callbackResult.AsyncState; 
      HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(callbackResult); 
      string responseString = ""; 
      Stream streamResponse = response.GetResponseStream(); 
      StreamReader reader = new StreamReader(streamResponse); 
      responseString = reader.ReadToEnd(); 
      streamResponse.Close(); 
      reader.Close(); 
      response.Close(); 
      string result = responseString; 
   } 
   catch (Exception e) 
   { 
 
   }
}


+       ex  {System.Net.WebException: The remote server returned an error: NotFound. ---> System.Net.WebException: The remote server returned an error: NotFound.
   at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
   at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClasse.<EndGetResponse>b__d(Object sendState)
   at System.Net.Browser.AsyncHelper.<>c__DisplayClass1.<BeginOnUI>b__0(Object sendState)
   --- End of inner exception stack trace ---
   at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
   at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at Track.View.StartTrac.GetResponsetStreamCallback(IAsyncResult callbackResult)} System.Exception {System.Net.WebException}
Posted
Updated 8-Nov-14 22:53pm
v3
Comments
austinbox 9-Nov-14 15:47pm    
Your URI is invalid if the remote server returns NotFound

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900