Hi i need send file to server i use this code
public void PostFile() {
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
// httpclient.
HttpPost httppost = new HttpPost("http://fastcalc.orionsource.ru/test.php");
File file = cache.getFileFromCache("citys.json");
FileEntity reqEntity = new FileEntity(file,"text/plain");
reqEntity.setContentType("text/plain");
httppost.setEntity(reqEntity);
System.out.println("executing request " + httppost.getRequestLine());
HttpResponse response;
try {
response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
System.out.println(response.getStatusLine());
if (resEntity != null) {
System.out.println(EntityUtils.toString(resEntity));
}
if (resEntity != null) {
resEntity.consumeContent();
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
httpclient.getConnectionManager().shutdown();
}
On server side code below
<?php
print 'Files:';
print_r($_FILES);
print '<br><br>';
print "Response:\n";
print_r($_REQUEST);
print '<br><br>';
?>
And on Android i get response
05-29 17:26:29.232: I/System.out(26823): executing request POST http://fastcalc.orionsource.ru/test.php HTTP/1.1
05-29 17:26:29.732: I/System.out(26823): HTTP/1.1 200 OK
05-29 17:26:29.732: I/System.out(26823): Files:Array
05-29 17:26:29.732: I/System.out(26823): (
05-29 17:26:29.732: I/System.out(26823): )
05-29 17:26:29.732: I/System.out(26823): <br><br>Response:
05-29 17:26:29.732: I/System.out(26823): Array
05-29 17:26:29.732: I/System.out(26823): (
05-29 17:26:29.732: I/System.out(26823): )
05-29 17:26:29.732: I/System.out(26823): <br><br>
I cant use MultipartEntity because it’s not included in any Android versions. It thirdpart library.
Someone give please link to tutorial which use only FileEntity.
Hi i have tries with image file to send on server. You can do one thing that convert your file into base64 string and send it to server and from server side try converting base64 to file
for reference how to convert to base64 ses my answer : how to send the image in an ImageView to a php server?