我能够做一个参数字符串的POST。我用下面的code:
I am able to do a POST of a parameters string. I use the following code:
String parameters = "firstname=john&lastname=doe";
URL url = new URL("http://www.mywebsite.com");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
connection.setRequestMethod("POST");
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
out.write(parameters);
out.flush();
out.close();
connection.disconnect();
不过,我需要做的二进制数据的POST(这是byte []的形式)。
However, I need to do a POST of binary data (which is in form of byte[]).
不知道如何改变上述code来实现它。 任何人都可以请帮我这个?
Not sure how to change the above code to implement it. Could anyone please help me with this?
这些链接可能会有所帮助:
These links might be helpful:
Android HttpClient的文件上传数据损坏和超时问题 的http://getablogger.blogspot.com/2008/01/android-how-to-post-file-to-php-server.html 的http://forum.springsource.org/showthread.php?108546-How-do-I-post-a-byte-array Android httpclient file upload data corruption and timeout issues http://getablogger.blogspot.com/2008/01/android-how-to-post-file-to-php-server.html http://forum.springsource.org/showthread.php?108546-How-do-I-post-a-byte-array下一篇:如何检测和管理来电(安卓)?