天鹅座通知 - 不支持application / json内容类型

时间:2016-08-22 14:38:49

标签: fiware-cygnus

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

$ 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

1 个答案:

答案 0 :(得分:2)

这是因为从天鹅座1.1.0开始只接受UTF-8字符集。要解决此问题,只需将Content-Type标题设置为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
.
.
.