Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未交付Java spark post参数_Java_Rest_Curl - Fatal编程技术网

未交付Java spark post参数

未交付Java spark post参数,java,rest,curl,Java,Rest,Curl,我刚刚开始编写我的第一个restAPI,我决定使用sparkapi。 但是我遇到了一个我无法解决的问题。 我正在尝试发布一些参数,例如 name - smth 我现在使用的是邮递员和卷发: curl -d "name=smth" http://localhost:8080/users 然而,无论是邮递员还是cURL,我都无法获得参数。spark上的参数仍然为空。我的路线是这样宣布的 post(new Route("/users") { @Override public Obj

我刚刚开始编写我的第一个restAPI,我决定使用sparkapi。 但是我遇到了一个我无法解决的问题。 我正在尝试发布一些参数,例如

name - smth
我现在使用的是邮递员和卷发:

curl -d "name=smth" http://localhost:8080/users
然而,无论是邮递员还是cURL,我都无法获得参数。spark上的参数仍然为空。我的路线是这样宣布的

post(new Route("/users") {
    @Override
    public Object handle(Request request, Response response) {
        String s = (String) request.attribute("name");
        return s;
    }
});
有人知道可能出了什么问题吗

从卷曲开始记录:

== 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

您可以使用-trace ascii curl.log参数来诊断curl实际发送的内容。我认为您可能需要在命令中使用-X POST来确保您正在使用POST。您确定它是正确的吗http://localhost:8080/users 在用户离开之前没有根路径?也许从一些GET请求开始,应该更容易诊断。GET请求起作用,post也起作用,当我不试图访问参数时。它给你一个404-所以post不起作用。你需要先解决这个问题。