【问题标题】:Google App Engine "Not Found" error on POST with url带有 url 的 POST 上的 Google App Engine“未找到”错误
【发布时间】:2014-10-18 01:34:12
【问题描述】:

我遇到了一个我无法弄清楚的奇怪问题。我在 Google App Engine 上设置了网络服务。我可以从 Google APIs Explorer 对其进行测试,然后我会取回数据。但是,当我复制并粘贴与下面的 API 链接关联的 URL 时(出于安全目的删除了应用程序信息),我在页面上收到“未找到”错误。它应该返回一些 JSON 数据。

有人知道为什么会这样吗?

这是我的 Servlet 代码

@ApiMethod(name="updateHighFive")
public Event addHighFive(@Named("eventid") int eventid, @Named("userid") int userid) throws NotFoundException{
    //parameters needed
    //eventid
    //title
    //description
    //categoryid
    Event event = new Event();
    event = MyDB.AddHighFive(eventid, userid);

    return event;
}

这是我的数据库连接的代码。

public static Event AddHighFive(int eventid, int userid) {
Event event = null;
Connection connection;
CallableStatement statement=null;
int rs = 0;

String callStatement = "{call AddHighFive(?,?)}";

try{
    connection=getConnection();
    statement = connection.prepareCall(callStatement);
    statement.setInt(1, eventid);
    statement.setInt(2, userid);
    rs = statement.executeUpdate();
    if(rs != 0){
        event = new Event();
        event.setId(eventid);
    }
    statement.close();
    connection.close();
}catch (SQLException ex){
    System.out.println("Error: " + ex.toString());
    System.out.println("Query: " + statement.toString());
}
return event;

}

请求

发布https://myapi-webservice-01.appspot.com/_ah/api/api/v1/addHighFive/4/1

X-JavaScript-User-Agent:Google API 浏览器

回应

200 正常

  • 显示标题 -

{

“id”:4,

"highFives": 0,

“去”:0,

“当前这里”:0,

"categoryid": 0,

“用户ID”:0,

“种类”:“myapi#resourcesItem”,

"etag": "\"4nNuVpsUM8obBGiS0qN7CVracwc/L7tNRSrZhr-ryKSf0HchvG1lWC4\""

}

【问题讨论】:

    标签: java google-app-engine servlets


    【解决方案1】:

    当您将 url 复制粘贴到浏览器时,您正在执行 GET 方法。尝试改用 curl -XPOST {url}。

    【讨论】:

    • 你为什么这么说?如果您使用的网站需要从页面中删除某些内容,您可以将参数传递到 URL,而 servlet 会处理其余的事情。我不知道“CURL”是什么,那对我有什么帮助?
    猜你喜欢
    • 1970-01-01
    • 2013-05-22
    • 2016-05-24
    • 2010-10-27
    • 2011-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多