您好我必须在谷歌应用引擎中部署一个servlet。但无法在以下代码中获得响应。我甚至没有在log中获得错误。以下是代码片段。
String executeHttpRequest(String jsonData, HttpPost httpPost,HttpServletResponse resp) throws UnsupportedEncodingException, IOException
{
resp.getWriter().println("inside execute http req1");
HttpResponse response=null;
String line = "";
StringBuffer result = new StringBuffer();
resp.getWriter().println("inside execute http req2");
httpPost.setEntity(new StringEntity(jsonData));
HttpClient client = HttpClientBuilder.create().build();
resp.getWriter().println("inside execute http req3");
response = client.execute(httpPost);
resp.getWriter().println("inside execute http req4");
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
while ((line = reader.readLine()) != null){ result.append(line); }
resp.getWriter().println("inside execute http req5");
resp.getWriter().println(result.toString());
String resultstring=result.toString();
return resultstring;
}
在此代码中,我没有收到回复
response = client.execute(httpPost);
直到那里一切都很顺利。但要点是需要从webservice获得响应。 首先我在jetty服务器上执行它。它工作正常。然后我在谷歌应用程序引擎中部署。