こんにちは。
Windows10でWPFのアプリケーションを開発しています。
Visual Studio 2015 Communityを使っています。
###前提・実現したいこと
HttpClientでChatWorkに投稿したいです。
Unauthorizedとなっています。
idとapiKeyは渡しているのですが、ほかに必要なものがあるのでしょうか?
###発生している問題・エラーメッセージ
StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { Vary: User - Agent Connection: keep - alive Date: Thu, 05 Jan 2017 08:29:55 GMT Server: nginx Content - Length: 32 Content - Type: application / json; charset = utf - 8 }
###該当のソースコード
C#
1string apiKey, roomId, id, message; 2 3var client = new HttpClient(); 4client.BaseAddress = new Uri("https://api.chatwork.com/v1/rooms/" + roomID + "/messages"); 5string useragent = "Shin-Mozilla/5.5 (Windows NeXT 2017; Trident/7.77; rv:11.1) like GeckohKamen"; 6 7var content = new FormUrlEncodedContent(new Dictionary<string, string> 8{ 9 { "User-Agent", useragent }, 10 { "X-ChatWorkToken", apiKey }, 11 { "id", id }, 12 { "body", message } 13}); 14var response = await client.PostAsync(client.BaseAddress, content);
###補足情報(言語/FW/ツール等のバージョンなど)
Microsoft Visual Studio Community 2015
Version 14.0.25424.00 Update 3
Microsoft .NET Framework
Version 4.6.01038
インストールしているバージョン:Community
Visual C# 2015 00322-20000-00000-AA575
Microsoft Visual C# 2015
です。
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/01/06 03:43