Hi there.

I make a Twitter app. for android.


I sent an update using HttpURLConnection.
but it isn't working.


my code is...

================================================================

String uri = "http://twitter.com/statuses/update.xml";;
HttpURLConnection connection = (HttpURLConnection) new URL
(uri).openConnection();

connection.setRequestMethod("POST");

connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "application/x-www-form-
urlencoded");

connection.setRequestProperty("Authorization", "Basic " + Base64.encode
(name + ":" + password));

String data = URLEncoder.encode("status") + "=" + URLEncoder.encode
("TEST!");

connection.setRequestProperty("User-Agent", "myTwitterApp");
connection.setRequestProperty("Content-Length", "" + data.getBytes
().length);

OutputStream oStream = connection.getOutputStream();
oStream.write(data.getBytes("UTF-8"));
oStream.flush();
oStream.close();

int responsecode = connection.getResponseCode();

switch (responsecode)
{
        case 200:
                break;
        case 403:
        case 404:
                Log.e("conn X", responsecode + " : " + 
connection.getResponseMessage
());
                return null;
        default:
                break;
}

==================================================================

when I make this code, I expect just one HTTP Post packet.
but there are two packet.

first packet is
    POST /statuses/update.xml HTTP/1.1 ~~ content-length: 41
second packet is
    status=The+First+update+from+myapp


When I call
OutputStream oStream = connection.getOutputStream();

the first packet is sent.

and then, when I call
int responsecode = connection.getResponseCode();

the second packet is sent.



so, responsecode is 403
  Client must provide a 'status' parameter with a value.



please help me.

Reply via email to