作者tsaiminghan (nahgnimiast)
看板AndroidDev
标题[问题] httppost
时间Mon Dec 24 22:49:35 2012
请问使用httppost时针对类似php的表格,
有参数要填,也可以上传本地端的档案。
参数比如
http://xxx.xxx.xx?aaa=bbb&ccc=eee
可是档案怎麽一起上传?
加参数有看到下面的方法
List<NameValuePair> nameValuePairs =
new ArrayList<NameValuePair>(valuepairs.size());
nameValuePairs.add(new BasicNameValuePair(XXX_KEY1, XXX_VALUE1));
nameValuePairs.add(new BasicNameValuePair(XXX_KEY2, XXX_VALUE2));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
档案有看到
fileInputStream = new FileInputStream(file);
InputStreamEntity reqEntity = new InputStreamEntity(fileInputStream,
file.length());
httppost.setEntity(reqEntity);
reqEntity.setContentType("binary/octet-stream");
httppost.setEntity(reqEntity);
不过这两个可以并用吗?
--
另外如果上传的是jpg或png之类的图片,type可以用binary吗?
type设jpeg和binary有什麽差?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 1.160.51.223
※ 编辑: tsaiminghan 来自: 1.160.51.223 (12/24 22:51)