我正在开发一个Android应用程序。在这里我遇到了将值发布到rest service的问题。我使用Namevaluepair绑定值来发布数据。
params.add(new BasicNameValuePair("businessName", businessname));
params.add(new BasicNameValuePair("address1", address1));
params.add(new BasicNameValuePair("businessphone", businessphone));
params.add(new BasicNameValuePair("email", email));
params.add(new BasicNameValuePair("zipCode", zipCode));
params.add(new BasicNameValuePair("locationcount", locationcount));
params.add(new BasicNameValuePair("businesstypeid", businesstypeid));
params.add(new BasicNameValuePair("firstnname", firstname));
像这样。当我在Android客户端中正确打印这些值时,它正确打印。但是在服务器上我得到空值。
try {
// http client
DefaultHttpClient httpClient = new DefaultHttpClient();
httpEntity = null;
HttpResponse httpResponse = null;
// Checking http request method type
if (method == POST) {
HttpPost httpPost = new HttpPost(url);
try
{
// adding post params
if (params != null) {
httpPost.setEntity(new UrlEncodedFormEntity(params));
System.out.println("this is post method.....................");
System.out.println(url);
System.out.println(params);
}
}
catch(UnsupportedEncodingException e)
{
e.printStackTrace();
}
try
{
httpResponse = httpClient.execute(httpPost);
Log.d("Http Response:", response.toString());
}
catch(ClientProtocolException e)
{
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
这是我的ServiceHandler课程。您可以告诉我为什么会遇到这种问题。请提前感谢您的建议。