Cygnus 通知 - application/json 内容类型不受支持

Cygnus notification - application/json content type not supported

当我向 Cygnus 发送通知时,我收到 400 响应消息 application/json content type not supported 但我在请求中设置了 Content-Type 和接受 headers。我已经在下面发布了请求和响应。

$ curl http://localhost:5050/notify -v -s -S --header 'Accept: application/json' --header 'Content-Type: application/json' --header "Fiware-Service: qsg" --header "Fiware-ServicePath: /testsink" -d @- <<EOF
> {
>     "subscriptionId" : "51c0ac9ed714fb3b37d7d5a8",
>     "originator" : "localhost",
>     "contextResponses" : [
>         {
>             "contextElement" : {
>                 "attributes" : [
>                     {
>                         "name" : "temperature",
>                         "type" : "float",
>                         "value" : "26.5"
>                     }
>                 ],
>                 "type" : "Room",
>                 "isPattern" : "false",
>                 "id" : "Room1"
>             },
>             "statusCode" : {
>                 "code" : "200",
>                 "reasonPhrase" : "OK"
>             }
>         }
>     ]
> }
> EOF
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 5050 (#0)
> POST /notify HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:5050
> Accept: application/json
> Content-Type: application/json
> Fiware-Service: qsg
> Fiware-ServicePath: /testsink
> Content-Length: 607
> 
* upload completely sent off: 607 out of 607 bytes
< HTTP/1.1 400 Bad request from client. application/json content type not supported
< Content-Type: text/html; charset=iso-8859-1
< Cache-Control: must-revalidate,no-cache,no-store
< Content-Length: 1489

这是因为从 cygnus 1.1.0 开始只接受 UTF-8 字符集。要解决此问题,只需将 Content-Type header 设置为 application/json; charset=utf-8

因此请求将变为:

$ curl http://localhost:5050/notify -v -s -S --header 'Accept: application/json' --header 'Content-Type: application/json; charset=utf-8' --header "Fiware-Service: qsg" --header "Fiware-ServicePath: /testsink" -d @- <<EOF
.
.
.