从Android Mobile发送的请求在服务器上没有得到任何响应

从Android Mobile发送的请求在服务器上没有得到任何响应,android,web-services,rest,httprequest,httpresponse,Android,Web Services,Rest,Httprequest,Httpresponse,我是android世界和移动应用服务器端编程的新手。我遇到了一个问题:-当任何android手机以url的形式向我发送请求时,我的服务器(ApacheTomcat)没有找到任何关于该请求的响应 我正在客户端(Android Mobile)编写以下代码:- publicstaticvoidrequestfordepartment() { ArrayList nameValuePairs=新的ArrayList(); 字符串iName=null; 字符串iprice=null; 字符串idPrice

我是android世界和移动应用服务器端编程的新手。我遇到了一个问题:-当任何android手机以url的形式向我发送请求时,我的服务器(ApacheTomcat)没有找到任何关于该请求的响应

我正在客户端(Android Mobile)编写以下代码:-

publicstaticvoidrequestfordepartment()
{
ArrayList nameValuePairs=新的ArrayList();
字符串iName=null;
字符串iprice=null;
字符串idPrice=null;
添加(新的BasicNameValuePair(“storeId”、“s0001”);
试一试{
System.out.println(“内部服务器try 1”);
//起始线用于服务器连接/通信
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost HttpPost=新
HttpPost(“http://192.168.1.3:8080/xybuy/rest/webservices/requestDepatment");
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
HttpResponse response=httpclient.execute(httppost);
HttpEntity=response.getEntity();
//终端线用于服务器连接/通信
InputStream=entity.getContent();
}捕获(例外e){
Log.e(“Log_标记”,“http连接错误”
+e.toString());
}
}
192.168.1.3:8080是我的终点。这是服务器端的web.xml文件

        <?xml version="1.0" encoding="UTF-8"?>
        <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"            xmlns="http://java.sun.com/xml/ns/javaee"    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID"    version="2.5">
  <display-name>FirstProject</display-name>
  <welcome-file-list>
  <welcome-file>index.html</welcome-file>
  <welcome-file>index.htm</welcome-file>
  <welcome-file>index.jsp</welcome-file>
  <welcome-file>index2.jsp</welcome-file>
  </welcome-file-list>
 <servlet>
 <servlet-name>ServletAdaptor</servlet-name>
 <servlet-class>
        com.sun.jersey.server.impl.container.servlet.ServletAdaptor</servlet-  class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ServletAdaptor</servlet-name>
<url-pattern>/REST/*</url-pattern>
</servlet-mapping>

第一个项目
index.html
index.htm
index.jsp
index2.jsp
伺服适配器
com.sun.jersey.server.impl.container.servlet.ServletAdapter
1.
伺服适配器
/休息/*

实际有效负载可以是JSON或XML。服务器是restful Web服务。

1)尝试向请求添加头,比如

httppost.setHeader("Content-Type", "application/x-www-form-urlencoded");
默认情况下,java会添加一些头,但有时这还不够


2) 如果您从本地PC在java项目中运行此代码,它是否有效?

@Eugene是对的,但您的问题完全不清楚。您可以说它是xml和json。这怎么可能?如果是xml,则需要一个“application/xml”作为内容类型,如果是json,则需要您的内容类型=“application/json”。

REST!=rest,这可能是原因吗?我不认为rest是原因……你怎么知道它是json还是xml?(假设您没有在请求头中指定它?)服务器端编码正在工作。我正在使用RESTfulwebservices。响应是json object,这意味着“我的服务器(apachetomcat)没有找到关于该请求的任何响应”。您的意思是Web服务器找不到对应于“storeId”、“s0001”的数据吗?
httppost.setHeader("Content-Type", "application/x-www-form-urlencoded");