关于安卓调用C#的WebService上传图片问题(不使用ksoap2) webservice安卓内存溢出上传图片 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 void submieGson(String users){ try { HttpClient httpClient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://*/jsonws/frank/ftocservice/getUserInfo"); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("users", users)); nameValuePairs.add(new BasicNameValuePair("file", getFileString())); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,HTTP.UTF_8)); HttpResponse response = httpClient.execute(httppost); System.out.println("rescode ="+response.getStatusLine().getStatusCode()); if (response.getStatusLine().getStatusCode() == 200) { String str = EntityUtils.toString(response.getEntity(),"utf-8"); System.out.println("json ========"+str); Message msg = Message.obtain(); msg.obj = str; mHandler.sendMessage(msg); } } catch (Exception e) { e.printStackTrace(); } }String getFileString() { String fileStream = null; FileInputStream fis; try { fis = new FileInputStream(Environment.getExternalStorageDirectory() .getPath() + "/QuickCheck/image/temp.png"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int count = 0; while ((count = fis.read(buffer)) >= 0) { baos.write(buffer, 0, count); } fis.close(); fileStream = new String(Base64.encode(baos.toByteArray(), Base64.DEFAULT)); // 进行Base64编码 } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return fileStream; }使用post进行提交 谢谢!post我也用过了,遇到什么问题我也忘了。。最后我还是用ksoap做了。。没时间等回复了。。分就都给你了。 小弟刚好处理这个问题,没使用ksoap2,按照同样的方法,服务器返回数据: Message: 请求处理时失败,求正解 QQ和邮箱:[email protected] android2.2如何实现横竖屏变换时调用两个不同的xml布局 android开发需要独显吗? 求几个android的小型项目+源码 如何通过应用来执行adb命令行 怎样获取到sdcard中的xml资源呢, sd 卡关联模拟器 andorid权限的问题 一个简单的layout问题,两行两列,其中一列合并的layout问题 墨迹天气 天气效果怎么实现 android好的架构的开源项目征集帖 Action如何换掉返回箭头 关于前台,后台,,前段,,,什么的
try { HttpClient httpClient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://*/jsonws/frank/ftocservice/getUserInfo");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("users", users));
nameValuePairs.add(new BasicNameValuePair("file", getFileString()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,HTTP.UTF_8));
HttpResponse response = httpClient.execute(httppost);
System.out.println("rescode ="+response.getStatusLine().getStatusCode());
if (response.getStatusLine().getStatusCode() == 200) {
String str = EntityUtils.toString(response.getEntity(),"utf-8");
System.out.println("json ========"+str);
Message msg = Message.obtain();
msg.obj = str;
mHandler.sendMessage(msg);
}
} catch (Exception e) {
e.printStackTrace();
}
}String getFileString() {
String fileStream = null;
FileInputStream fis;
try {
fis = new FileInputStream(Environment.getExternalStorageDirectory()
.getPath() + "/QuickCheck/image/temp.png"); ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int count = 0;
while ((count = fis.read(buffer)) >= 0) {
baos.write(buffer, 0, count);
}
fis.close();
fileStream = new String(Base64.encode(baos.toByteArray(),
Base64.DEFAULT)); // 进行Base64编码
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return fileStream;
}使用post进行提交
谢谢!post我也用过了,遇到什么问题我也忘了。。最后我还是用ksoap做了。。没时间等回复了。。分就都给你了。