2、在请求中添加上传文件所需的额外参数,这样服务器才能够正确接收文件。使用帆毁httppost上传文件时,还需要注意文件大小的念唯限制,以及仔轿培编码格式的设置等问题。
给拆凳http post传参,参考以下二个实例:哪模//serverURL url地址
HttpPost httpPost = new HttpPost(serverURL)
//param 为参数
StringEntity entity = new StringEntity(param)
entity.setContentType("application/x-www-form-urlencoded")
httpPost.setEntity(entity)
HttpResponse httpResponse = httpClient.execute(httpPost)
还可以用map作为参数
List<NameValuePair>旅缓旅 formparams = new ArrayList<NameValuePair>()
if(param!=null){
Set set = param.keySet()
Iterator iterator = set.iterator()
while (iterator.hasNext()) {
Object key = iterator.next()
Object value = param.get(key)
formparams.add(new BasicNameValuePair(key.toString(), value.toString()))
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)