Skip to content

Instantly share code, notes, and snippets.

@fantasticswallow
Created December 28, 2013 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fantasticswallow/8156173 to your computer and use it in GitHub Desktop.
Save fantasticswallow/8156173 to your computer and use it in GitHub Desktop.
Update with Mediaができない
Public Async Function PostMediaAsync(uri As String, param As Dictionary(Of String, String), fileName As String, media As Byte()) As Task(Of HttpResponseMessage)
Using cli As New HttpClient
cli.Timeout = TimeSpan.FromSeconds(Timeout)
If param Is Nothing Then param = New Dictionary(Of String, String)
Dim boud = System.Environment.TickCount.ToString
Dim content As New MultipartFormDataContent("--" + boud)
For Each x In param
content.Add(New StringContent(x.Value), """" + x.Key + """")
Next
Dim binary = New ByteArrayContent(media)
binary.Headers.ContentType = New Headers.MediaTypeHeaderValue("image/" + fileName.Split("."c).Last.ToLower)
Await binary.LoadIntoBufferAsync()
content.Add(binary, """media[]""", """" + fileName + """")
cli.DefaultRequestHeaders().Authorization = New Headers.AuthenticationHeaderValue("OAuth", CreateAuthorization(New Uri(uri), "POST", param))
cli.DefaultRequestHeaders.Add("Content-Length", media.Length.ToString)
'cli.DefaultRequestHeaders.Add("Content-Type", "multipart/form-data; boundary=--" + boud)
Return Await cli.PostAsync(New Uri(uri), content)
End Using
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment