posting updates via js

0 views
Skip to first unread message

john

unread,
Nov 12, 2008, 7:46:14 PM11/12/08
to Twitter Development Talk
Hi there,

I'm working in XUL, so I'm not dealing with cross-domain security
issues. I am issuing a request using the following code:

var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if(req.readyState == 4 && req.status == 200) {
try {
// do some stuff
} catch(e) {
// don't really care
}
}
}
req.open('POST','http://twitter.com/statuses/update.json');
req.setRequestHeader("Authorization", "Basic " + encodedAuth);
req.setRequestHeader("Connection", "close");
req.send("status=" + escape("foo"));

Using NetCat, I am comparing this request with a successful one (using
LWP), and it seems fine, but it's returning a 500 error from Twitter.
Here's the POST:

POST /statuses/update.json HTTP/1.1
Host: twitter.com
User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:
1.8.1.17) Gecko/20080829 Firefox/2.0.0.17
Accept: text/xml,application/xml,application/xhtml+xml,text/
html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: close
Authorization: Basic [base64 encoded user/pass, i've checked it's
good]
Content-Length: 10
Content-Type: application/xml
Pragma: no-cache
Cache-Control: no-cache

status=foo

I tried it with the original "Connection: keep-alive" to no avail. Is
it obvious what's going wrong here?

Thanks in advance!

John

fastest963

unread,
Nov 12, 2008, 11:02:14 PM11/12/08
to Twitter Development Talk
I just noticed something shouldn't the
Content-Type: application/x-www-form-urlencoded

This could be the problem.

fastest963

unread,
Nov 12, 2008, 10:59:47 PM11/12/08
to Twitter Development Talk
HTTP 500 Error usually means its a server error and its not your
fault, however it may have something to do with your status post data.
If you could, post the return headers and/or body. Also, it may have
just been a simple problem with Twitter at the time.
I just tested the API and it works fine for me:
http://twitter.com/fastest963/status/1003271037
Maybe Alex or other devs can shed some light on something wrong with
the Headers you sent.

John Greene

unread,
Nov 13, 2008, 9:17:06 AM11/13/08
to twitter-deve...@googlegroups.com
That was it, thanks!

John

Reply all
Reply to author
Forward
0 new messages