Created
February 9, 2016 16:40
-
-
Save bfaist/ba5cdb5e234a8d1fb0e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Mojo::UserAgent; | |
use Mojo::JSON qw/encode_json/; | |
my $token = 'NOT_A_TOKEN'; | |
my $ws_url = 'wss://stream.watsonplatform.net/speech-to-text/api/v1/recognize?watson-token=' . $token . '&model=en-US_BroadbandModel'; | |
my $ua = Mojo::UserAgent->new(); | |
$ua->websocket($ws_url => sub { | |
my ($ua, $tx) = @_; | |
print 'WebSocket handshake failed!' and return unless $tx->is_websocket; | |
$tx->on(message => sub { print 'Message'; }); | |
$tx->send(encode_json({ 'action' => 'start' })); | |
}); | |
Mojo::IOLoop->start unless Mojo::IOLoop->is_running; | |
OUTPUT: | |
-- Non-blocking request (https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?watson-token=NOT_A_TOKEN&model=en-US_BroadbandModel) | |
-- Connect 24aec8e6200ede92a0434409eff0447a (https://stream.watsonplatform.net:443) | |
-- Client >>> Server (https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?watson-token=NOT_A_TOKEN&model=en-US_BroadbandModel) | |
GET /speech-to-text/api/v1/recognize?watson-token=NOT_A_TOKEN&model=en-US_BroadbandModel HTTP/1.1\x0d | |
User-Agent: Mojolicious (Perl)\x0d | |
Connection: Upgrade\x0d | |
Accept-Encoding: gzip\x0d | |
Content-Length: 0\x0d | |
Sec-WebSocket-Version: 13\x0d | |
Host: stream.watsonplatform.net\x0d | |
Sec-WebSocket-Key: IDU1NjU5Nzk4NzYyODg5MA==\x0d | |
Upgrade: websocket\x0d | |
\x0d | |
-- Client <<< Server (https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?watson-token=NOT_A_TOKEN&model=en-US_BroadbandModel) | |
HTTP/1.1 400 Internal Server Error\x0d | |
Content-Type: text/html\x0d | |
X-DP-Watson-Tran-ID: csf_platform_prod_dp01-1081212625\x0d | |
WWW-Authenticate: Basic realm="IBM Watson Gateway Log-in"\x0d | |
X-Backside-Transport: FAIL FAIL\x0d | |
Connection: close\x0d | |
\x0d | |
-- Client <<< Server (https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?watson-token=NOT_A_TOKEN&model=en-US_BroadbandModel) | |
<HTML><HEAD><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><TITLE>Watson Error</TITLE></HEAD><BODY><HR><p>Invalid access to resource - /speech-to-text/api/v1/recognize?watson-token=NOT_A_TOKEN&model=en-US_BroadbandModel</p><p>User access not Authorized.</p><p>Gateway Error Code : ERCD04-NOAUTHHDR-PLTFRMREQ</p><p>Unable to communicate with Watson.</p><p>Request URL : /speech-to-text/api/v1/recognize?watson-token=NOT_A_TOKEN&model=en-US_BroadbandModel</p><p>Error Id : csf_platform_prod_dp01-1081212625</p><p>Date-Time : 2016-02-09T11:29:13-05:00</p></BODY></HTML> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment