我是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是我的終點。這是在服務器端
<?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我的web.xml文件。而服務器是寧靜的web服務。
REST!=休息,可能是原因嗎? – njzk2
我不認爲REST是原因...... – user206516
你怎麼知道它是json還是xml? (鑑於您沒有在請求頭中指定它) – njzk2