我有一个 android 应用程序,如果我有任何异常,它会将其写入文件(文件存储在设备的内部存储器中).....现在我想知道是否可以将此文件发送到我的本地主机服务器.
提前致谢
编辑:下面的代码是我用来上传图片的代码......
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Bitmap bm=bitmap;
bm.compress(CompressFormat.PNG, 75, bos);
byte[] data = bos.toByteArray();
HttpClient httpClient = new DefaultHttpClient();
String url="192.168.1.1**";
HttpPost postRequest = new HttpPost(url+"uploadimage");
ByteArrayBody bab = new ByteArrayBody(data, imageName);
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("uploadfile", bab);
//reqEntity.addPart("photoCaption", new StringBody("sfsdfsdf"));
postRequest.setEntity(reqEntity);
HttpResponse response = httpClient.execute(postRequest);
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
String sResponse;
StringBuilder s = new StringBuilder();
while ((sResponse = reader.readLine()) != null) {
s = s.append(sResponse);
}
System.out.println("Response: " + s);
} catch (Exception e) {
// handle exception here
Log.e(e.getClass().getName(), e.getMessage());
}
同样我想上传一个文件(文本文件)。