2016-08-22 63 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 
. 
. 
. 
相關問題