2017-02-02 5 views
0

私は紺碧のイベントハブにデータを送信するアプリケーションで作業しています。 http://sreesharp.com/send-events-from-android-app-to-microsoft-azure-event-hubs/AndroidからのAzureイベントハブの承認

しかし、私はOkHttp使用する接続コードを更新:これはここにブログの記事に似て

public void sendMessageOkHttp(String dataPacket, String connectionString, String sasKey){ 

    // Instantiate the OkHttp Client 
    OkHttpClient client = new OkHttpClient(); 

    // Create the body of the message to be send 
    RequestBody formBody = new FormBody.Builder() 
      .add("message", dataPacket) 
      .build(); 

    // Now create the request and post it 
    Request request = new Request.Builder() 
      .header("Authorization", sasKey) 
      .url(connectionString) 
      .post(formBody) 
      .build(); 
    Log.i(TAG,"about to send message"); 
    // Now try to send the message 
    try { 
     Log.i(TAG,"sending message...."); 
     Response response = client.newCall(request).execute(); 
     Log.i(TAG,"message sent"); 
     Log.i("Azure Response",String.valueOf(response.message())); 

     // Do something with the response. 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
} 

は、しかし、これは「無許可」イベントハブからの応答を返します。私が使用しているsasキーは、sendおよびlistenのアクセス許可で作成した共有アクセスポリシー用です。それが主キーです。

私はここで間違っていますか? Azureのドキュメントは、Android互換ではないAzure Javaライブラリ(つまり、Java 1.8が必要)を使用することに重点を置いているため、このケースでは本当に役に立ちません。

答えて

関連する問題