安卓:发送通过HTTP POST一个byte []数组 [英] Android: Sending a byte[] array via Http POST

查看:1794
本文介绍了安卓:发送通过HTTP POST一个byte []数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够做一个参数字符串的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 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

这篇关于安卓:发送通过HTTP POST一个byte []数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆