此URL-Google App Engine不支持HTTP方法GET

时间:2015-03-17 16:24:29

标签: google-app-engine servlets cloud

   public class MailHandlerServlet extends HttpServlet { 
    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {

    try {

    Properties props = new Properties();
    Session session1 = Session.getDefaultInstance(props, null);
    MimeMessage message = new MimeMessage(session1, req.getInputStream());

     //Extract out the important fields from the Mime Message
     String subject = message.getSubject();    
    String contentType = message.getContentType();

    printParts(message);
    //Parse out the Multiparts
    //Perform business logic based on the email
    }
    catch (IOException | MessagingException ex) {

     }
    }

    private static void printParts(Part p) throws IOException, MessagingException {
    Object o = p.getContent();

    if (o instanceof String) {
        out.println("This is a String");
    out.println((String)o);
    }
    else if (o instanceof Multipart) {
    out.println("This is a Multipart");
    Multipart mp = (Multipart)o;

    int count = mp.getCount();
    for (int i = 0; i < count; i++) {
    printParts(mp.getBodyPart(i));
    }
    }
    else if (o instanceof InputStream) {
    out.println("This is just an input stream");
    InputStream is = (InputStream)o;
    int c;
    while ((c = is.read()) != -1)
    out.write(c);
    }
    }

    }

上面的代码给出了这样的错误......&#34;此方法不支持HTTP方法GET&#34;请帮我修理一下。我正在GAE中部署它。我正在编写此代码以接收邮件到我的appspot.com。我已经更新了我的appengine-web.xml和web.xml。当我尝试运行该页面时,它会显示此错误。

2 个答案:

答案 0 :(得分:1)

此servlet中没有doGet方法,您正在对它进行GET调用。您要么必须进行POST调用,要么实现GET方法。例如:

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    doPost(request, response);
}

答案 1 :(得分:0)

最近,我还在研究名为DrEdit的谷歌应用引擎示例Web应用程序,我也得到了这个错误。我编写了以下代码以使其正常工作。

@Override
  public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws IOException, ServletException {
      System.out.println("start of GoogleDriveAuth:::::::");
      credentialManager = new CredentialManager(
                getClientSecrets(), TRANSPORT, JSON_FACTORY);
      handleCallbackIfRequired(req, resp);

您需要为您的应用程序编写类似的doGet方法。希望它有所帮助!