Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3961696
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:00:22+00:00 2026-05-20T03:00:22+00:00

I have 2 methods at the moment 1 to post a file, and another

  • 0

I have 2 methods at the moment 1 to post a file, and another to post some text, they are below

Post the data…

public void postData() {  
    // Create a new HttpClient and Post Header  

    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    EditText et = (EditText) findViewById(R.id.entry);
    String enteredName = et.getText().toString();
    gender();
    category();
    nameValuePairs.add(new BasicNameValuePair("name",enteredName));
    nameValuePairs.add(new BasicNameValuePair("gender",radio));
    nameValuePairs.add(new BasicNameValuePair("cat",radio2));

    //http post
    try{
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://10.0.2.2:90/upload.php");
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpclient.execute(httppost);

    } catch (ClientProtocolException e) {  
        // TODO Auto-generated catch block      
    } catch (IOException e) {  
        // TODO Auto-generated catch block  
    }  


              }

post the file…

public void postFile(){
    File file = new File(filedir2);
    try {
             System.out.println(filedir2);
             HttpClient client = new DefaultHttpClient();  
             String postURL = "http://10.0.2.2:90/mobileupload.php";                 
             HttpPost post = new HttpPost(postURL); 


         FileBody bin = new FileBody(file);
         MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);  
         reqEntity.addPart("image", bin);
         post.setEntity(reqEntity);  
         HttpResponse response = client.execute(post);  
         HttpEntity resEntity = response.getEntity();  
         if (resEntity != null) {    
                   Log.i("RESPONSE",EntityUtils.toString(resEntity));
             }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

I have made a php file that combines both mobileupload.php and upload.php, i was just wondering if there was a way i could get this into one method and just do one post?

Help would be appreciated

Thanks

James

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T03:00:22+00:00Added an answer on May 20, 2026 at 3:00 am

    You can use something like this:

    File file = new File("FileToSend.txt");
    HttpClient client = new HttpClient();
    
    String url = "http://www.yourdomain.com/destination.php";
    PostMethod postMethod = new PostMethod(url);
    
    Part[] parts = {new FilePart(file.getName(), file)};
    postMethod.setParameter("name", "value"); // set parameters like this instead in separate call
    
    postMethod.setRequestEntity( new MultipartRequestEntity(parts, postMethod.getParams()));
    
    int status = client.executeMethod(postMethod);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have some methods that call File.Copy, File.Delete, File.Exists, etc. How can we test
Some existing web services I consume have methods that look something like this: List<Employee>
I've created some MbUnit Test Fixtures that have SetUp methods marked with the SetUp
I have methods with more than one parameter that are guarded against bad input
I'm creating my own JavaScript Array-like object and I have methods that call closures.
I have several service classes that have static methods and offer a service to
Assume I have 10 Methods and 10 Properties. Is there a way to add
Does Python have extension methods like C#? Is it possible to call a method
If two users edit the same wiki topic, what methods have been used in
I'm hosting my first WCF service in IIS. I have two methods, 1 to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.