This version works. Its the
vb.net version of Seans C# code
Public Sub UploadProfileImage(ByVal photo As Byte(), ByVal
username As String, ByVal pwd As String)
System.Net.ServicePointManager.Expect100Continue = False
Dim request As HttpWebRequest = DirectCast
(HttpWebRequest.Create("
http://twitter.com/account/
update_profile_image.xml"), HttpWebRequest)
request.PreAuthenticate = True
request.AllowWriteStreamBuffering = True
Dim boundary As String = System.Guid.NewGuid().ToString()
request.Credentials = New NetworkCredential(username, pwd)
request.ContentType = String.Format("multipart/form-
data;boundary={0}", boundary)
request.Method = "POST"
' Build Contents for Post
Dim header As String = "--" & boundary
Dim footer As String = "--" & boundary & "--"
Dim contents As New StringBuilder()
' Image
contents.AppendLine(header)
contents.AppendLine(String.Format("Content-Disposition:form-
data); name=""image""); filename=""{0}""", "twitterProfilePhoto.jpg"))
contents.AppendLine("Content-Type: image/jpeg")
contents.AppendLine()
contents.AppendLine(System.Text.Encoding.GetEncoding
("iso-8859-1").GetString(photo))
' Footer
contents.AppendLine(footer)
' Data that is sent with the post
Dim bytes As Byte() = Encoding.GetEncoding
("iso-8859-1").GetBytes(contents.ToString())
request.ContentLength = bytes.Length
Using requestStream As Stream = request.GetRequestStream()
requestStream.Write(bytes, 0, bytes.Length)
requestStream.Flush()
requestStream.Close()
Using response As WebResponse = request.GetResponse()
Using reader As New StreamReader
(response.GetResponseStream())
Dim s As String = reader.ReadToEnd()
End Using
End Using
End Using
End Sub