java - How to upload a file using httppost FileEntity working with PHP server -


my java code on client is:

fileentity entity = new fileentity(zipfile, contenttype); post.addheader(entity.getcontenttype()); post.setentity(entity); httpresponse response = httpclient.execute(post); 

i want receive using php on apache server. have no idea how set first value in $_files[" "]["tmp_name"] in php function move_uploaded_file($_files[" "]["tmp_name"],$upload_file). have seen others asked same question.but answer not enough. waiting answer,thanks lot!

i'm ready own test , it's been done on android downloading apache httpclient, should'nt problem case.

i included httpclient.jar , httpmime.jar in 'libs'-folder.

the important thing set part-name on mime-part of multipart-message. first part of assoc. php array.

        httpclient httpclient = new defaulthttpclient();         httpclient.getparams().setparameter(                 coreprotocolpnames.protocol_version, httpversion.http_1_1);          httppost httppost = new httppost(url_string);         file file = new file(file_string);          multipartentity mpentity = new multipartentity();         contentbody cbfile = new filebody(file);         mpentity.addpart("userfile", cbfile);          httppost.setentity(mpentity);         system.out                 .println("executing request " + httppost.getrequestline());         httpresponse response = httpclient.execute(httppost);         httpentity resentity = response.getentity();          statusline statusline = response.getstatusline();         system.out.println(statusline);         if (resentity != null) {             system.out.println(entityutils.tostring(resentity));         }         if (resentity != null) {             resentity.consumecontent();         }          httpclient.getconnectionmanager().shutdown();          return statusline != null ? statusline.getstatuscode() : 0; 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -