我应该如何在 KAA 中实现 Rest API
How should I implement Rest API in KAA
我使用 Kaa 沙盒发送通知。
我必须在 window 终端上 运行 这些代码:
curl -v -S -u devuser:devuser123 -F 'notification={"applicationId":"3","schemaId":"4","topicId":"1","type":"USER"}; type=application/json' -F file=@notification.json "http://192.168.10.49:8080/kaaAdmin/rest/api/sendNotification" | python -mjson.tool
而内容Json文件是根据schemaId:
{"message" : "Hello world!"}
提示:我的命令和json文件是同一个文件夹!
当我在 windows 终端上 运行 curl 命令时出现错误(HTTP/1.1 400 所需的请求部分 'notification' 不存在)
这是运行宁和给出结果时的完整信息:
C:\Users6\mycurl>curl -v -S -u devuser:devuser123 -F 'notification={"applicationId":"3","schemaId":"4","topicId":"1","type":"USER"}; type=application/json' -F file=@notification.json "http://192.168.10.49:8080/kaaAdmin/rest/api/sendNotification" | python -mjson.tool
* timeout on name lookup is not supported
* getaddrinfo(3) failed for type=application:80
* Couldn't resolve host 'type=application'
* Closing connection 0
curl: (6) Couldn't resolve host 'type=application'
* timeout on name lookup is not supported
* Trying 192.168.10.49...
* TCP_NODELAY set
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to 192.168.10.49 (192.168.10.49) port 8080 (#1)
* Server auth using Basic with user 'devuser'
> POST /kaaAdmin/rest/api/sendNotification HTTP/1.1
> Host: 192.168.10.49:8080
> Authorization: Basic ZGV2dXNlcjpkZXZ1c2VyMTIz
> User-Agent: curl/7.53.1
> Accept: */*
> Content-Length: 394
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------96aee635439b1f3c
>
< HTTP/1.1 100 Continue
} [312 bytes data]
< HTTP/1.1 400 Required request part 'notification' is not present
< Date: Tue, 18 Jul 2017 13:20:44 GMT
< Set-Cookie: JSESSIONID=19eircy8uykvr1f0lnmj4fah7r;Path=/
< Content-Type: text/html; charset=ISO-8859-1
< Cache-Control: must-revalidate,no-cache,no-store
< Content-Length: 402
< Server: Jetty(9.2.2.v20140723)
* HTTP error before end of send, stop sending
<
{ [402 bytes data]
100 796 100 402 100 394 1288 1262 --:--:-- --:--:-- --:--:-- 1430
* Closing connection 1
Expecting value: line 1 column 1 (char 0)
请指导我解决这个问题。
我找到了正确的解决方案。
我尝试使用 ssh 命令连接到 kaa 服务器。
1- 您可以通过以下方式访问 SSH:
$ ssh kaa@127.0.0.1 -p 2222
2- 然后输入:
用户名: kaa
密码:kaa
并且在新的和旧的调用 REST API.
中几乎没有改变发送通知命令就解决了这个问题
3- 此命令已更改:
curl -v -S -u devuser:devuser123 -X POST --header 'Content-Type:multipart/form-data' -F'notification={"applicationId":"3","schemaId":"65564","topicId":"1","type":"USER"};type=applicatin/json' --header 'Accept:application/json' 'http://localhost:8080/kaaAdmin/rest/api/sendNotification' -F file=@notification.json
然后正确反应的结果:
我使用 Kaa 沙盒发送通知。
我必须在 window 终端上 运行 这些代码:
curl -v -S -u devuser:devuser123 -F 'notification={"applicationId":"3","schemaId":"4","topicId":"1","type":"USER"}; type=application/json' -F file=@notification.json "http://192.168.10.49:8080/kaaAdmin/rest/api/sendNotification" | python -mjson.tool
而内容Json文件是根据schemaId:
{"message" : "Hello world!"}
提示:我的命令和json文件是同一个文件夹!
当我在 windows 终端上 运行 curl 命令时出现错误(HTTP/1.1 400 所需的请求部分 'notification' 不存在)
这是运行宁和给出结果时的完整信息:
C:\Users6\mycurl>curl -v -S -u devuser:devuser123 -F 'notification={"applicationId":"3","schemaId":"4","topicId":"1","type":"USER"}; type=application/json' -F file=@notification.json "http://192.168.10.49:8080/kaaAdmin/rest/api/sendNotification" | python -mjson.tool
* timeout on name lookup is not supported
* getaddrinfo(3) failed for type=application:80
* Couldn't resolve host 'type=application'
* Closing connection 0
curl: (6) Couldn't resolve host 'type=application'
* timeout on name lookup is not supported
* Trying 192.168.10.49...
* TCP_NODELAY set
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to 192.168.10.49 (192.168.10.49) port 8080 (#1)
* Server auth using Basic with user 'devuser'
> POST /kaaAdmin/rest/api/sendNotification HTTP/1.1
> Host: 192.168.10.49:8080
> Authorization: Basic ZGV2dXNlcjpkZXZ1c2VyMTIz
> User-Agent: curl/7.53.1
> Accept: */*
> Content-Length: 394
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------96aee635439b1f3c
>
< HTTP/1.1 100 Continue
} [312 bytes data]
< HTTP/1.1 400 Required request part 'notification' is not present
< Date: Tue, 18 Jul 2017 13:20:44 GMT
< Set-Cookie: JSESSIONID=19eircy8uykvr1f0lnmj4fah7r;Path=/
< Content-Type: text/html; charset=ISO-8859-1
< Cache-Control: must-revalidate,no-cache,no-store
< Content-Length: 402
< Server: Jetty(9.2.2.v20140723)
* HTTP error before end of send, stop sending
<
{ [402 bytes data]
100 796 100 402 100 394 1288 1262 --:--:-- --:--:-- --:--:-- 1430
* Closing connection 1
Expecting value: line 1 column 1 (char 0)
请指导我解决这个问题。
我找到了正确的解决方案。
我尝试使用 ssh 命令连接到 kaa 服务器。
1- 您可以通过以下方式访问 SSH:
$ ssh kaa@127.0.0.1 -p 2222
2- 然后输入:
用户名: kaa
密码:kaa
并且在新的和旧的调用 REST API.
中几乎没有改变发送通知命令就解决了这个问题3- 此命令已更改:
curl -v -S -u devuser:devuser123 -X POST --header 'Content-Type:multipart/form-data' -F'notification={"applicationId":"3","schemaId":"65564","topicId":"1","type":"USER"};type=applicatin/json' --header 'Accept:application/json' 'http://localhost:8080/kaaAdmin/rest/api/sendNotification' -F file=@notification.json
然后正确反应的结果: