Advertisement
Guest User

Untitled

a guest
Apr 27th, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 4.63 KB | None | 0 0
  1.  
  2.             Dim fs As System.IO.FileStream = System.IO.File.Open(user, IO.FileMode.Open, IO.FileAccess.Read)
  3.             Dim buff(fs.Length - 1) As Byte
  4.             If fs.Length > 0 Then
  5.                 fs.Read(buff, 0, fs.Length - 1)
  6.                 fs.Close()
  7.                 imagesrc = Convert.ToBase64String(buff)
  8.                 imagesrc = System.Web.HttpUtility.UrlEncode(imagesrc)
  9.                 buff = Nothing
  10.                 fs = Nothing
  11.             End If
  12.  
  13.             Dim length As Long = 0
  14.             Dim boundary As String = "---------------------------" & DateTime.Now.Ticks.ToString
  15.             Dim boundarybytes As Byte() = System.Text.Encoding.ASCII.GetBytes(vbCr & vbLf & "--" & boundary & vbCr & vbLf)
  16.  
  17.             Dim httpWebRequest2 As HttpWebRequest = DirectCast(WebRequest.Create("https://upload.twitter.com/i/tweet/create_with_media.iframe"), HttpWebRequest)
  18.             httpWebRequest2.Host = "upload.twitter.com"
  19.             httpWebRequest2.ContentType = "multipart/form-data; boundary=" & boundary
  20.             httpWebRequest2.Method = "POST"
  21.             httpWebRequest2.KeepAlive = True
  22.             httpWebRequest2.Headers("Accept-Encoding") = "gzip,deflate,sdch"
  23.             httpWebRequest2.Headers("Accept-Language") = "en-GB,en-US;q=0.8,en;q=0.6"
  24.             httpWebRequest2.Headers("Cache-Control") = "max-age=0"
  25.             httpWebRequest2.Headers("Origin") = "https://twitter.com"
  26.  
  27.             If proxy <> "Real" Then httpWebRequest2.Proxy = myProxy
  28.             httpWebRequest2.Timeout = PROXY_TIMEOUT
  29.             httpWebRequest2.ReadWriteTimeout = PROXY_TIMEOUT
  30.             httpWebRequest2.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
  31.             httpWebRequest2.Referer = "https://twitter.com/"
  32.             httpWebRequest2.Credentials = System.Net.CredentialCache.DefaultCredentials
  33.             httpWebRequest2.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0"
  34.             httpWebRequest2.CookieContainer = container
  35.             httpWebRequest2.CookieContainer.Add(cookies)
  36.  
  37.             Dim rs As Stream = httpWebRequest2.GetRequestStream()
  38.  
  39.             Dim formdataTemplate As String = "Content-Disposition: form-data; name=""{0}""" & vbCr & vbLf & vbCr & vbLf & "{1}"
  40.  
  41.             Dim nvc As New NameValueCollection
  42.             nvc.Add("post_authenticity_token", token)
  43.             nvc.Add("iframe_callback", "window.top.swift_tweetbox_1397247065837")
  44.             nvc.Add("in_reply_to_status_id", "")
  45.             nvc.Add("impression_id", "")
  46.             nvc.Add("earned", "")
  47.             nvc.Add("page_context", "")
  48.             nvc.Add("status", message)
  49.             nvc.Add("media_data[]", imagesrc)
  50.             For Each key As String In nvc.Keys
  51.                 rs.Write(boundarybytes, 0, boundarybytes.Length)
  52.                 Dim formitem As String = String.Format(formdataTemplate, key, nvc(key))
  53.                 Dim formitembytes As Byte() = System.Text.Encoding.UTF8.GetBytes(formitem)
  54.                 rs.Write(formitembytes, 0, formitembytes.Length)
  55.             Next
  56.             rs.Write(boundarybytes, 0, boundarybytes.Length)
  57.             Dim headerTemplate As String = "Content-Disposition: form-data; name=""media_empty""; filename=""" & vbCr & vbLf & "Content-Type: application/octet-stream" & vbCr & vbLf & vbCr & vbLf
  58.             Dim headerbytes As Byte() = System.Text.Encoding.UTF8.GetBytes(headerTemplate)
  59.             rs.Write(headerbytes, 0, headerbytes.Length)
  60.  
  61.             rs.Write(boundarybytes, 0, boundarybytes.Length)
  62.             Dim formitem1 As String = String.Format(formdataTemplate, "place_id", "")
  63.             Dim formitembytes1 As Byte() = System.Text.Encoding.UTF8.GetBytes(formitem1)
  64.             rs.Write(formitembytes1, 0, formitembytes1.Length)
  65.  
  66.             Dim trailer As Byte() = System.Text.Encoding.ASCII.GetBytes(vbCr & vbLf & "--" & boundary & "--" & vbCr & vbLf)
  67.             rs.Write(trailer, 0, trailer.Length)
  68.             rs.Close()
  69.  
  70.             Dim wresp As WebResponse = Nothing
  71.             Try
  72.                 wresp = httpWebRequest2.GetResponse()
  73.                 Dim stream2 As Stream = wresp.GetResponseStream()
  74.                 Dim reader2 As New StreamReader(stream2)
  75.                 Debug.Print(String.Format("File uploaded, server response is: {0}", reader2.ReadToEnd()))
  76.             Catch ex As Exception
  77.                 Debug.Print("Error uploading file " & ex.Message)
  78.                 If wresp IsNot Nothing Then
  79.                     wresp.Close()
  80.                     wresp = Nothing
  81.                 End If
  82.             Finally
  83.                 httpWebRequest2 = Nothing
  84.             End Try
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement