package com.test.client;
import java.io.File;
import java.io.IOException;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.ParseException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.DefaultHttpClient;
public class httpPost {
public static int post(String pathToOurFile,String urlServer) throws ParseException, IOException{
int code = 0;
HttpClient httpclient = new DefaultHttpClient();
HttpPost post = new HttpPost(urlServer);
FileBody fileBody = new FileBody(new File(pathToOurFile));
MultipartEntity entity = new MultipartEntity();
entity.addPart("upfile", fileBody);
post.setEntity(entity);
HttpResponse response = httpclient.execute(post);
if(HttpStatus.SC_OK == response.getStatusLine().getStatusCode()){
code = HttpStatus.SC_OK;
}
httpclient.getConnectionManager().shutdown();
return code;
}
}
import java.io.File;
import java.io.IOException;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.ParseException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.DefaultHttpClient;
public class httpPost {
public static int post(String pathToOurFile,String urlServer) throws ParseException, IOException{
int code = 0;
HttpClient httpclient = new DefaultHttpClient();
HttpPost post = new HttpPost(urlServer);
FileBody fileBody = new FileBody(new File(pathToOurFile));
MultipartEntity entity = new MultipartEntity();
entity.addPart("upfile", fileBody);
post.setEntity(entity);
HttpResponse response = httpclient.execute(post);
if(HttpStatus.SC_OK == response.getStatusLine().getStatusCode()){
code = HttpStatus.SC_OK;
}
httpclient.getConnectionManager().shutdown();
return code;
}
}