Profile image update returns 500 Internal Server Error

24 views
Skip to first unread message

Toby Glenn

unread,
Dec 16, 2008, 3:48:03 PM12/16/08
to Twitter Development Talk
I get the 500 Internal Server Error when I try to update a profile
image. I am trying to do it using c# and I am not sure what is going
on. Here is a network sniff of my request:
No. Time Source Destination
Protocol Info
657 2.775514 10.50.50.230 128.121.146.100
HTTP POST /account/update_profile_image.xml HTTP/1.1 (JPEG JFIF
image)

Frame 657 (85 bytes on wire, 85 bytes captured)
Ethernet II, Src: 00:21:70:6b:00:61 (00:21:70:6b:00:61), Dst:
Watchgua_30:99:52 (00:90:7f:30:99:52)
Destination: Watchgua_30:99:52 (00:90:7f:30:99:52)
Source: 00:21:70:6b:00:61 (00:21:70:6b:00:61)
Type: IP (0x0800)
Internet Protocol, Src: 10.50.50.230 (10.50.50.230), Dst:
128.121.146.100 (128.121.146.100)
Transmission Control Protocol, Src Port: hfcs (4900), Dst Port: http
(80), Seq: 28021, Ack: 26, Len: 31
[Reassembled TCP Segments (28051 bytes): #586(210), #621(129), #622
(1260), #623(1260), #627(1260), #628(1260), #629(1260), #630(1260),
#632(1260), #633(1260), #634(1260), #635(1260), #636(1260), #638
(1260), #639(1260), #640(1260), #641(1260]
Hypertext Transfer Protocol
MIME Multipart Media Encapsulation, Type: multipart/form-data,
Boundary: "----------8cb2dd5e785fac4"
[Type: multipart/form-data]
First boundary: ------------8cb2dd5e785fac4\r\n
Encapsulated multipart part: (image/jpeg)
Boundary: \r\n------------8cb2dd5e785fac4\r\n
Encapsulated multipart part:

Alex Payne

unread,
Dec 16, 2008, 7:56:18 PM12/16/08
to twitter-deve...@googlegroups.com
HTTP headers and such are a bit more helpful for debugging this, thanks!

--
Alex Payne - API Lead, Twitter, Inc.
http://twitter.com/al3x

avon

unread,
Jan 4, 2009, 9:41:37 AM1/4/09
to Twitter Development Talk
Has this been solved? Im getting the same error when I try to upload
an image

Alex Payne

unread,
Jan 4, 2009, 4:35:32 PM1/4/09
to twitter-deve...@googlegroups.com
It seems like a number of different HTTP client libraries have issues
with this method. However, it works just fine via curl, which leads me
to believe that the problem is either with those libraries with the
programmer's use of the libraries.

--

avon

unread,
Jan 17, 2009, 10:18:15 AM1/17/09
to Twitter Development Talk
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
Reply all
Reply to author
Forward
0 new messages