Last active
January 1, 2016 14:09
-
-
Save ChiiAyano/8156235 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
public async Task<HttpResponseMessage> SendAsync(IDictionary<string, object> parameter, AsyncOAuth.AccessToken accessToken, string footer) | |
{ | |
var client = new HttpClient(); | |
var boundary = DateTime.Now.ToString("MMddHHmmss") + new Random().Next().ToString(); | |
var content = new MultipartFormDataContent(boundary); | |
foreach (var item in parameter) | |
{ | |
if (item.Value is string) | |
{ | |
content.Add(new StringContent(item.Value as string), "\"" + this.MessageKeyName + "\""); | |
} | |
else if (item.Value is Stream) | |
{ | |
var sendData = await Task.Factory.StartNew<byte[]>(() => | |
{ | |
var ms = item.Value as MemoryStream; | |
// ストリームをバイト配列にする | |
ms.Seek(0, SeekOrigin.Begin); | |
var send = new List<byte>(); | |
while (true) | |
{ | |
var rb = new byte[1024]; | |
var readBytes = ms.Read(rb, 0, rb.Length); | |
if (readBytes <= 0) | |
break; | |
send.AddRange(rb); | |
} | |
return send.ToArray(); | |
}); | |
content.Add(new ByteArrayContent(sendData), "\"" + this.MediaKeyName + "\"", string.Format("\"upload_{0}.jpg\"", boundary)); | |
} | |
} | |
var result = await OAuthUtility.CreateOAuthClient(this.ConsumerKey, this.ConsumerSecret, accessToken) | |
.PostAsync(this.ServiceUri, content); | |
var response = await result.Content.ReadAsStringAsync(); | |
Console.WriteLine(response); | |
return result; | |
} |
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
response: | |
{"errors":[{"code":189,"message":"Error creating status."}]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment