我刚刚开始编写我的第一个restAPI,我决定使用Spark API。 但我遇到了一个我无法解决的问题。 我试图发布一些参数,例如。
name - smth
我现在正在使用Postman和cURL:
curl -d "name=smth" http://localhost:8080/users
然而,无论是Postman还是cURL,我都无法获得参数。 spark上的参数仍然为null。我的路线被宣布为
post(new Route("/users") {
@Override
public Object handle(Request request, Response response) {
String s = (String) request.attribute("name");
return s;
}
});
任何人都知道可能出现什么问题?
从cURL记录:
== Info: About to connect() to localhost port 8080 (#0)
== Info: Trying ::1...
== Info: connected
== Info: Connected to localhost (::1) port 8080 (#0)
=> Send header, 219 bytes (0xdb)
0000: POST /users HTTP/1.1
0016: User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0
0056: OpenSSL/0.9.8y zlib/1.2.5
0072: Host: localhost:8080
0088: Accept: */*
0095: Content-Length: 9
00a8: Content-Type: application/x-www-form-urlencoded
00d9:
=> Send data, 9 bytes (0x9)
0000: item=smth
== Info: upload completely sent off: 9 out of 9 bytes
<= Recv header, 24 bytes (0x18)
0000: HTTP/1.1 404 Not Found
<= Recv header, 40 bytes (0x28)
0000: Content-Type: text/html; charset=UTF-8
<= Recv header, 21 bytes (0x15)
0000: Content-Length: 105
<= Recv header, 32 bytes (0x20)
0000: Server: Jetty(9.0.2.v20130417)
<= Recv header, 2 bytes (0x2)
0000:
<= Recv data, 105 bytes (0x69)
0000: <html><body><h2>404 Not found</h2>The requested route [/users] h
0040: as not been mapped in Spark</body></html>
== Info: Connection #0 to host localhost left intact
== Info: Closing connection #0