[英]IBM Bluemix and websocket 400 error
我正在嘗試使用websocket模塊將node.js與IBM Watson Speech to text api接口。 當我嘗試連接時,出現400錯誤,我不確定為什么...我以前從未使用過websocket。 這是我的代碼創建套接字並嘗試連接
var WebSocketClient = require('websocket').client,
client = new WebSocketClient(),
token = 'myToken==',
wsri = 'wss://stream.watsonplatform.net/speech-to-text/api/v1/recognize?watson-token=' + token;
//some event handlers for on connect and on connectFailed
client.connect(wsri, null, null, null, null);
這是我得到的回應
Connect Error: Error: Server responded with a non-101 status: 400
Response Headers Follow:
content-type: text/html
x-dp-watson-tran-id: csf_platform_prod_dp01-735083801
set-cookie: Watson-DPAT=this_is_a_cookie; path=/speech-to-text/api; secure; HttpOnly
www-authenticate: Basic realm="IBM Watson Gateway Log-in"
x-backside-transport: FAIL FAIL
connection: close
任何想法如何解決這一問題??
編輯更新:德國人的回答是正確的。 我沒有調用授權端點來獲取令牌,而是試圖使用我的bluemix憑證。
為了使用WebSocket,您首先需要獲取一個調用authorization
api的token
。 然后,您將該token
添加到url
。
Websocket網址為:
wss://stream.watsonplatform.net/speech-to-text/api/v1/recognize?watson-token=TOKEN
可以在其中創建TOKEN
地方(例如curl):
curl -u USERNAME:PASSWORD "https://stream.watsonplatform.net/authorization/api/v1/token?url=https://stream.watsonplatform.net/speech-to-text/api"
USERNAME
和PASSWORD
是您的服務憑據。
這基本上是一個GET
請求
https://stream.watsonplatform.net/authorization/api/v1/token
帶有url
查詢參數,該參數是您要為其獲取令牌的服務。 在這種情況下:
https://stream.watsonplatform.net/speech-to-text/api
如果您使用的是nodejs,我建議您使用watson-developer-cloud
npm模塊。 請看一下此片段, 該片段向您展示如何使用“語音轉文本”服務進行實時轉錄。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.