将音频文件和值从android发送到服务器

时间:2013-05-21 12:24:19

标签: java android

我知道在Android上传音频,我可以这样做:

final byte[] data = out.toByteArray();
String urlString = "http://localhost/voiceupload.php";
HttpPost postRequest = new HttpPost(urlString);
postRequest.setEntity(new  ByteArrayEntity(data)); //data is a byte array containing sound in the form of bytearray
HttpClient client = new DefaultHttpClient();

上传简单值我可以这样做:

ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("callid", "8123069127952"));
UrlEncodedFormEntity formEntity = null;
try {
formEntity = new UrlEncodedFormEntity(postParameters);
} catch (UnsupportedEncodingException e1) {
  e1.printStackTrace();
 }
httpPost.setEntity(formEntity);
client.execute(postRequest)

现在我想在一个帖子请求中发送两个。我的意思是我想发送一个或多个变量值和一个声音文件。我可以这样做吗?

1 个答案:

答案 0 :(得分:0)

不确定。在这篇文章中看到我的回答: Save a received picture to a folder on a web server 只需用声音文件替换图像文件即可。 如果它只传递一个值,即文件名,您可以根据需要添加任意数量的名称 - 值对。