I’ve been searching around now for quite a while and can’t get any straight answer as to how to call a java servlet from the windows phone 7 API? I’ve read about ‘WebClient’ and ‘HttpWebRequest’ but the implementations seem to differ for normal C# and the windows phone.
The method (or rather empty shell) I have looks like this:
public Login(string userName, password){
string servletUrl = "http://172.12.5.35:8080/SomeService/login?u="+userName+"&p="+password;
//Somehow to call the servlet>>
}
I’m a Java coder, although the syntax is almost identical, I’ve been thrown in the deep end here coding for the windows phone.
Also maybe worth mentioning that the servlet returns JSON. How does one handle that in C#?
Thanks in advance for any push in the right direction!
My Attempt using HttpWebRequest:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(servletUrl);
HttpWebResponse response = (HttpWebRequest)request.BeginGetResponse();
But I see that ‘BeginGetResponse()’ takes 2 arguments namely AsyncCallback & object state. What are these two arguments and what would mine be in this case?
Here is the sample code which makes a web request to get JSON data
and the DownloadStringCompleted handler is,
In the above code,
SomeObjectis the Class to which you want to convert the JSON data to.Additionally, paste your json URL or json Data in this link to generate the suitable class for you.