I am trying to call web service api from android app, code shown below:
ArrayList<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(2);
nameValuePair.add(new BasicNameValuePair("check", "chk"));
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost(HTTP_CHECK);
post.setEntity(new UrlEncodedFormEntity(nameValuePair));
httpClient.execute(post);
HttpResponse httpres = httpClient.execute(post);
This is my web service API on asp.net
[WebMethod]
public string HelloWorld2(String check)
{
return "SuccessCheck";
}
Host Server is Godaddy. The above method worked previously. But now it gives the error on an app -
System.InvalidOperationException:Missing Parameter:check.
How it says that parameter is missing. The parameter is passed as namevaluepair. I don't know what the problem is? However, it works perfectly on localhost.
Service methods which do not have any parameters work well on a server as well as on local host. Now when I change the android code as below
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost(HTTP_CHECK + "?check=chk");
httpClient.execute(post);
HttpResponse httpres = httpClient.execute(post);
Now it works well on a server as well as host. As I am passing the parameter with URL as given above and not using a name-value pair.
What is the problem in the first scenario and why it suddenly changed? Please help.