こんにちは。
Windows10でWPFのアプリケーションを開発しています。
Visual Studio 2017 Communityを使っています。
###前提・実現したいこと
WebClientをHttpClinetに書き換えたいです。
WebClientでは投稿できています。
###発生している問題・エラーメッセージ
responseは下記の通り。
Id = 350, Status = RanToCompletion, Method = "{null}", Result = "StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:\r\n{\r\n Connection: keep-alive\r\n Access-Control-Allow-Origin: *\r\n Pragma: no-cache\r\n Referrer-Policy: no-referrer\r\n Strict-Transport-Security: max-age=31536000; includeSubDomains; preload\r\n Vary: Accept-Encoding\r\n X-Accepted-OAuth-Scopes: chat:write:bot,post\r\n X-Content-Type-Options: nosniff\r\n X-OAuth-Scopes: read,client,admin,identify,post,apps\r\n X-Cache: Miss from cloudfront\r\n X-Amz-Cf-Id: abcde12f3gh4pijklmnobq5r-stuv6wxyz7a8bcdefg90h12i3j-kl==\r\n Cache-Control: no-store, must-revalidate, no-cache, private\r\n Date: Sun, 02 Jul 2017 06:12:27 GMT\r\n Server: Apache\r\n Via: 1.1 12d12121212e1b1d122e1qr12aa2c0cb.cloudfront.net (CloudFront)\r\n Content-Length: 30\r\n Content-Type: application/json; charset=utf-8\r\n Expires: Mon, 26 Jul 1997 05:00:00 GMT\r\n}"
###該当のソースコード
C#
1 private void sendAsync() 2 { 3 url = "targeturl"; 4 var content = new FormUrlEncodedContent(new Dictionary<string, string> 5 { 6 { "A", "" }, 7 { "B", "" }, 8 { "C", "" } 9 }); 10 var client = new HttpClient(); 11 client.DefaultRequestHeaders.Add("ContentType", "application/json;charset=UTF-8"); 12 var response = client.PostAsync(url, content); 13 } 14 15 private void sendByWebclient() 16 { 17 url = "targeturl"; 18 19 //文字コードを指定する 20 var encoding = Encoding.GetEncoding("shift_jis"); 21 //POST送信する文字列を作成 22 string postData = ""; 23 24 var wc = new WebClient(); 25 //文字コードを指定する 26 wc.Encoding = encoding; 27 //ヘッダにContent-Typeを加える 28 wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); 29 //データを送信し、また受信する 30 string resText = wc.UploadString(url, postData); 31 wc.Dispose(); 32 } 33
###補足情報(言語/FW/ツール等のバージョンなど)
Microsoft Visual Studio Community 2017
Version 15.0.26228.9 D15RTWSVC
Microsoft .NET Framework
Version 4.6.01586
です。
よろしくお願いします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/07/02 09:14
2017/07/02 15:23