0
我在這,如果我有任何異常,將其寫入到一個文件(文件存儲在設備內部存儲器).....現在我想知道,如果一個Android應用程序它可能發送這個文件到我的本地主機服務器。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());
}
同樣地,我想上傳一個文件(文本文件)。
請告訴我在服務器上的代碼? –