Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Dim fs As System.IO.FileStream = System.IO.File.Open(user, IO.FileMode.Open, IO.FileAccess.Read)
- Dim buff(fs.Length - 1) As Byte
- If fs.Length > 0 Then
- fs.Read(buff, 0, fs.Length - 1)
- fs.Close()
- imagesrc = Convert.ToBase64String(buff)
- imagesrc = System.Web.HttpUtility.UrlEncode(imagesrc)
- buff = Nothing
- fs = Nothing
- End If
- Dim length As Long = 0
- Dim boundary As String = "---------------------------" & DateTime.Now.Ticks.ToString
- Dim boundarybytes As Byte() = System.Text.Encoding.ASCII.GetBytes(vbCr & vbLf & "--" & boundary & vbCr & vbLf)
- Dim httpWebRequest2 As HttpWebRequest = DirectCast(WebRequest.Create("https://upload.twitter.com/i/tweet/create_with_media.iframe"), HttpWebRequest)
- httpWebRequest2.Host = "upload.twitter.com"
- httpWebRequest2.ContentType = "multipart/form-data; boundary=" & boundary
- httpWebRequest2.Method = "POST"
- httpWebRequest2.KeepAlive = True
- httpWebRequest2.Headers("Accept-Encoding") = "gzip,deflate,sdch"
- httpWebRequest2.Headers("Accept-Language") = "en-GB,en-US;q=0.8,en;q=0.6"
- httpWebRequest2.Headers("Cache-Control") = "max-age=0"
- httpWebRequest2.Headers("Origin") = "https://twitter.com"
- If proxy <> "Real" Then httpWebRequest2.Proxy = myProxy
- httpWebRequest2.Timeout = PROXY_TIMEOUT
- httpWebRequest2.ReadWriteTimeout = PROXY_TIMEOUT
- httpWebRequest2.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
- httpWebRequest2.Referer = "https://twitter.com/"
- httpWebRequest2.Credentials = System.Net.CredentialCache.DefaultCredentials
- httpWebRequest2.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0"
- httpWebRequest2.CookieContainer = container
- httpWebRequest2.CookieContainer.Add(cookies)
- Dim rs As Stream = httpWebRequest2.GetRequestStream()
- Dim formdataTemplate As String = "Content-Disposition: form-data; name=""{0}""" & vbCr & vbLf & vbCr & vbLf & "{1}"
- Dim nvc As New NameValueCollection
- nvc.Add("post_authenticity_token", token)
- nvc.Add("iframe_callback", "window.top.swift_tweetbox_1397247065837")
- nvc.Add("in_reply_to_status_id", "")
- nvc.Add("impression_id", "")
- nvc.Add("earned", "")
- nvc.Add("page_context", "")
- nvc.Add("status", message)
- nvc.Add("media_data[]", imagesrc)
- For Each key As String In nvc.Keys
- rs.Write(boundarybytes, 0, boundarybytes.Length)
- Dim formitem As String = String.Format(formdataTemplate, key, nvc(key))
- Dim formitembytes As Byte() = System.Text.Encoding.UTF8.GetBytes(formitem)
- rs.Write(formitembytes, 0, formitembytes.Length)
- Next
- rs.Write(boundarybytes, 0, boundarybytes.Length)
- Dim headerTemplate As String = "Content-Disposition: form-data; name=""media_empty""; filename=""" & vbCr & vbLf & "Content-Type: application/octet-stream" & vbCr & vbLf & vbCr & vbLf
- Dim headerbytes As Byte() = System.Text.Encoding.UTF8.GetBytes(headerTemplate)
- rs.Write(headerbytes, 0, headerbytes.Length)
- rs.Write(boundarybytes, 0, boundarybytes.Length)
- Dim formitem1 As String = String.Format(formdataTemplate, "place_id", "")
- Dim formitembytes1 As Byte() = System.Text.Encoding.UTF8.GetBytes(formitem1)
- rs.Write(formitembytes1, 0, formitembytes1.Length)
- Dim trailer As Byte() = System.Text.Encoding.ASCII.GetBytes(vbCr & vbLf & "--" & boundary & "--" & vbCr & vbLf)
- rs.Write(trailer, 0, trailer.Length)
- rs.Close()
- Dim wresp As WebResponse = Nothing
- Try
- wresp = httpWebRequest2.GetResponse()
- Dim stream2 As Stream = wresp.GetResponseStream()
- Dim reader2 As New StreamReader(stream2)
- Debug.Print(String.Format("File uploaded, server response is: {0}", reader2.ReadToEnd()))
- Catch ex As Exception
- Debug.Print("Error uploading file " & ex.Message)
- If wresp IsNot Nothing Then
- wresp.Close()
- wresp = Nothing
- End If
- Finally
- httpWebRequest2 = Nothing
- End Try
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement