【发布时间】:2013-01-07 10:49:27
【问题描述】:
我是 android 世界和移动应用程序服务器端编程的新手。我遇到了一个问题:- 当从任何 android 手机向我发送 url 形式的请求时,我的服务器(Apache tomcat)没有找到关于该请求的任何响应。
我正在客户端(Android Mobile)编写以下代码:-
public static void requestForDepartment()
{
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
String iName = null;
String iprice = null;
String idPrice = null;
nameValuePairs.add(new BasicNameValuePair("storeId","s0001"));
try {
System.out.println("inside server try 1");
// start - line is for sever connection/communication
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new
HttpPost("http://192.168.1.3:8080/xybuy/rest/webservices/requestDepatment");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
// end - line is for sever connection/communication
InputStream is = entity.getContent();
} catch (Exception e) {
Log.e("log_tag", "Error in http connection "
+ 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>
实际负载可以是 JSON 或 XML。并且服务器是restful webservices。
【问题讨论】:
-
REST != 休息,这可能是原因吗?
-
我不认为 REST 是原因......
-
怎么知道是json还是xml? (假设您没有在请求标头中指定它?)
标签: android web-services rest httprequest httpresponse