0
我有以下的Servlet:球衣號碼:WAR不接受POST
// Sets the path to base URL + /servlet
@Path("/servlet")
public class Servlet
{
// This method is called if TEXT_PLAIN is request
@POST
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void storeData(@FormParam("data1") String data1,
@FormParam("data2") String data2,
@Context HttpServletResponse servletResponse) throws IOException
{
//Does stuff here
}
}
我有以下客戶:
//Create HTTP Client
DefaultHttpClient httpclient = new DefaultHttpClient();
// Use SSL
httpclient = sslClient(httpclient);
// Prepare the post statement
HttpPost httppost = new HttpPost(url);
// Add auth header with utility account information
httppost.addHeader("Authorization", "Basic " + Base64.encodeToString(("username" + ":"
+ "password").getBytes(), Base64.NO_WRAP));
postParameters.add(new BasicNameValuePair("data1", data1));
postParameters.add(new BasicNameValuePair("data2", data2));
httppost.setEntity(new UrlEncodedFormEntity(postParameters));
// Execute the post request
HttpResponse response = httpclient.execute(httppost);
服務器測試代碼PHP - 格拉布斯的字符串值 「鍵」 和將該值輸出到文件
$content =$_POST['data1'];
$file = "newtext.txt";
$Saved_File = fopen($file, 'w');
fwrite($Saved_File, $content);
fclose($Saved_File);
PHP測試腳本起作用。它收到帖子,我可以在服務器上的文本文件中查看data1。但是Servlet @POST方法似乎沒有被調用。
有沒有辦法調試呢?任何人有任何想法如何讓這個工作?我不知道我是否應該使用@FormParam或@QueryParam或@HeaderParam。 @POST方法如何被調用?