Advertisement
Guest User

Untitled

a guest
Dec 12th, 2011
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. Public Function SetTwitterAppSettings(ByVal AppID As String, ByVal AppName As String, ByVal AppDescription As String, ByVal AppURL As String, ByVal callback_url As String, ByVal form_build_id As String, ByVal form_token As String) As String
  2. Dim boundary As String = "---------------------------" & DateTime.Now.Ticks.ToString("x")
  3. Dim newLine As String = System.Environment.NewLine
  4. Dim boundaryBytes As Byte() = System.Text.Encoding.ASCII.GetBytes(newLine & "--" & boundary & newLine)
  5. Dim request As Net.HttpWebRequest = Net.WebRequest.Create("https://dev.twitter.com/apps/" & AppID & "/settings")
  6. ' Set Proxy Details
  7. Dim myProxy As New WebProxy(Proxy, Port)
  8. myProxy.Credentials = New NetworkCredential(ProxyUser, ProxyPass)
  9. request.Proxy = myProxy
  10. ' Request Settings
  11. request.Method = "POST"
  12. request.ContentType = "multipart/form-data; boundary=" & boundary
  13. ' request.KeepAlive = True
  14. request.AllowAutoRedirect = False
  15. request.Timeout = MaxTimeout
  16. request.CookieContainer = cookies
  17. request.UserAgent = Useragent
  18. request.AllowWriteStreamBuffering = False
  19. request.Referer = "https://dev.twitter.com/apps/" & AppID & "/settings"
  20. Dim ms As New MemoryStream()
  21. ms.Write(boundaryBytes, 0, boundaryBytes.Length)
  22. Dim headerTemplate As String = "Content-Disposition: form-data; name=""{0}""; description=""{1}""; url=""{2}""; files[image]""; filename=""; access_level=1; callback_url=""{3}""; organization=""""; organization_url=""""; op=""Update this Twitter application's settings""; form_build_id=""{4}""; form_token=""{5}""; form_id=""twitter_apps_form_settings""; "
  23. Dim header As String = String.Format(headerTemplate, AppName, AppDescription, AppURL, callback_url, form_build_id, form_token)
  24. MessageBox.Show(header)
  25. Dim headerBytes As Byte() = System.Text.Encoding.UTF8.GetBytes(header)
  26. ms.Write(headerBytes, 0, headerBytes.Length)
  27. Dim length As Long = ms.Length
  28. request.ContentLength = length
  29. Using requestStream As IO.Stream = request.GetRequestStream()
  30. Dim bheader() As Byte = ms.ToArray()
  31. requestStream.Write(bheader, 0, bheader.Length)
  32. requestStream.Close()
  33. End Using
  34. Dim response As Net.WebResponse = Nothing
  35. Dim responseText = ""
  36. response = request.GetResponse()
  37. Using responseStream As IO.Stream = response.GetResponseStream()
  38. Using responseReader As New IO.StreamReader(responseStream)
  39. responseText = responseReader.ReadToEnd()
  40. End Using
  41. End Using
  42. response.Close()
  43. response = Nothing
  44. request = Nothing
  45. Return responseText
  46. End Function
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement