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

  • SEARCH
  • Home
  • 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 6331619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:06:15+00:00 2026-05-24T18:06:15+00:00

I want to post among other data a String variable to a PHP file

  • 0

I want to post among other data a String variable to a PHP file by using the HttpConnection stuff. The first data is the byte[] data returned from a recordstore. So it should be posted alone. So how to post the String variable also ?

  • 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-24T18:06:17+00:00Added an answer on May 24, 2026 at 6:06 pm

    You can pass the data to a PHP file using GET or POST methods.

    Get method is the easy way to pass simple data. Using GET you can add the variable to the URL

    Example:

    192.168.1.123/myproject/uploads/treatphoto.php?myVariable1=MyContent&myVariable2=MyContent2
    

    And in PHP:

    $content1 = $_GET['myVariable1'];
    $content2 = $_GET['myVariable2'];
    

    Also the content of “MyContent” needs to be an string encoded. using any UrlEncoder.

    To pass a byte[] array using this method you need to convert the byte array to an string encoded in some printable encoding like base64

    The GET method also has a sort limit of data that can be passed safely (usually 2048 bytes)

    The other method “POST” is more complex (but not a lot), way to add more data.

    You need to prepare the HttpConnection to pass the data as POST.
    Also the data stored in urlParamenters need to be according to the url enconding.
    Passing the data using post is similar to GET but instead of adding all the variables next to the url the varuiables are added in the Stream of the httpConnection request.

    example of the java code:

    String urlParameters = "myVariable1=myValue1&myVariable2=myValue2";
    
    HttpURLConnection connection = null;  
    try {
      url = new URL(targetURL);
      connection = (HttpURLConnection)url.openConnection();
    
      // Use post and add the type of post data as URLENCODED
      connection.setRequestMethod("POST");
      connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
    
      // Optinally add the language and the data content
      connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length));
      connection.setRequestProperty("Content-Language", "en-US");  
    
      // Set the mode as output and disable cache.
      connection.setUseCaches (false);
      connection.setDoInput(true);
      connection.setDoOutput(true);
    
      //Send request
      DataOutputStream wr = new DataOutputStream (connection.getOutputStream ());
      wr.writeBytes (urlParameters);
      wr.flush ();
      wr.close ();
    
    
      // Get Response    
      // Optionally you can get the response of php call.
      InputStream is = connection.getInputStream();
      BufferedReader rd = new BufferedReader(new InputStreamReader(is));
      String line;
      StringBuffer response = new StringBuffer(); 
      while((line = rd.readLine()) != null) {
        response.append(line);
        response.append('\r');
      }
      rd.close();
      return response.toString();
    

    The php is similar, you only need to replace $_GET by $_POST:

    $content1 = $_POST['myVariable1'];
    $content2 = $_POST['myVariable2'];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to POST an URL using CURL and php. There is a big
I have an ASP.NET application in which i want to post data using jQuery
I have a winForms NET3.5SP1 app, and want to POST data to a PHP
I want to post some data via javascript to another domain. Something like: http://www.othersite.com/submitfunnyname?name=blah
I want to ignore the post form in the django's internatonalization. I am using
Among other text and visual aids on a form submission, post-validation, I'm coloring my
Recently I have been working on a project where, among other things, we want
I have a form which contains among others: <form id=new_basic_ad class=new_basic_ad method=post enctype=multipart/form-data action=/basic_ads
I want to make a form like this, and i want to post the
If I have a HTTP based RESTful service and I want to POST a

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.