2016-08-22 61 views
2

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

$ 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 

回答

2

这是因为从cygnus 1.1.0开始只接受UTF-8字符集。为了解决这个问题,只需设置Content-Typeapplication/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 
. 
. 
. 
相关问题