Twitter basic authorisation not working?
URL url = new URL("http://twitter.com/statuses/update.xml");
HttpURLConnection conn = (HttpURLConnection) url.o开发者_Python百科penConnection();
conn.setDoOutput(true);
String cridentials =
new sun.misc.BASE64Encoder().encode((username + ":" + password).getBytes());
conn.setRequestProperty ("Authorization", "Basic " + cridentials);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(status);
wr.flush();
wr.close();
Why is above code for updating twitter status is not working ?
I am running it on google app engine.
You'll find this easier if you the java twitter library. Even if you don't use it, you can read it and see how to do this much more straightforwardly with Apache Commons Http Client.
精彩评论