我正在尝试从我的 android 向 GAE 上的服务器发出 http 发布请求。
在 android 端,帖子似乎运行良好,但在服务器端,doPost(...) 永远不会被调用。谁能告诉我为什么?
这是我的相关android代码:
protected Integer doInBackground(View... arg0)
{
try
{
HttpClient httpClient = new DefaultHttpClient();
// HttpPost httpPost = new HttpPost("http://elf-security.appspot.com");
HttpPost httpPost = new HttpPost("http://elf-security.appspot.com/gae_hellowordl");
// HttpPost httpPost = new HttpPost("http://localhost:8888/gae_hellowordl");
httpPost.addHeader("test", "Success!");
Log.i(TAG, "Just about to send http request to " + httpPost.getURI());
HttpResponse httpResponse = httpClient.execute(httpPost);
Log.i(TAG, "Received http response..");
Log.i(TAG, httpResponse.toString());
} catch (ClientProtocolException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
return null;
}
这是我的相关服务器代码:
public class GAE_HelloWordlServlet extends HttpServlet
{
private Logger LOG;
public GAE_HelloWordlServlet()
{
LOG = Logger.getLogger("GAE_HelloWordlServlet");
LOG.info("GAE_HelloWordlServlet()");
}
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException
{
LOG.info("doGet(): request test header: " + req.getHeader("test"));
}
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException
{
LOG.info("doPost(): request test header: " + req.getHeader("test"));
}
}
提前致谢!
编辑
这是我的 web.xml 文件:
<?xml version="1.0" encoding="utf-8" standalone="no"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>GAE_HelloWordl</servlet-name>
<servlet-class>gae.helloworld.GAE_HelloWordlServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>GAE_HelloWordl</servlet-name>
<url-pattern>/*</url-pattern>
<!-- <url-pattern>/gae_hellowordl</url-pattern> -->
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>SystemServiceServlet</servlet-name>
<servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
<init-param>
<param-name>services</param-name>
<param-value/>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SystemServiceServlet</servlet-name>
<url-pattern>/_ah/spi/*</url-pattern>
</servlet-mapping>
</web-app>