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 8216493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:08:44+00:00 2026-06-07T12:08:44+00:00

im trying to find a way to post username and password using json rather

  • 0

im trying to find a way to post username and password using json rather than normal http post that im currently using. i have being going through most of the tutorials and examples to undestand but yet i was unable to get an idea. i have json phasers available to get the data from my sql but not the post json.

thank you for the help

following is the currently used json post

EditText uname = (EditText) findViewById(R.id.log_Eu_name);
            String username = uname.getText().toString();

            EditText pword = (EditText) findViewById(R.id.log_Epass);
            String password = pword.getText().toString();

            String result = new String();
            result = "";

            ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            nameValuePairs
                    .add(new BasicNameValuePair("username", username));
            nameValuePairs
                    .add(new BasicNameValuePair("password", password));

            InputStream is = null;
            try {
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost("http://www.loshwickphotography.com/log.php");
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();
                is = entity.getContent();
                Log.w("SENCIDE", "Execute HTTP Post Request");

                String str = inputStreamToString(
                        response.getEntity().getContent()).toString();
                Log.w("SENCIDE", str);

                if (str.toString().equalsIgnoreCase("true")) {
                    Log.w("SENCIDE", "TRUE");
                    Toast.makeText(getApplicationContext(),
                            "FUking hell yeh!", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(getApplicationContext(),
                            "Sorry it failed", Toast.LENGTH_SHORT).show();
                }
            } catch (Exception e) {

                Log.e("log_tag", "Error in http connection " + e.toString());
            }
            try {
                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(is, "iso-8859-1"), 8);
                StringBuilder sb = new StringBuilder();
                String line = null;
                while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");
                }
                is.close();

                result = sb.toString();

            } catch (Exception e) {
                Log.e("log_tag", "Error converting result " + e.toString());
            }

            try {
                if (result != null) {
                    JSONArray jArray = new JSONArray(result);
                    Log.i("log_tag", Integer.toString(jArray.length()));
                    for (int i = 0; i < jArray.length(); i++) {
                        JSONObject json_data = jArray.getJSONObject(i);

                    }
                } else {
                    Toast.makeText(getApplicationContext(), "NULL",
                            Toast.LENGTH_SHORT).show();
                }

            } catch (JSONException e) {
                Log.e("log_tag", "Error parsing data " + e.toString());

            }
        }

        private Object inputStreamToString(InputStream is) {
            // TODO Auto-generated method stub
            String line = "";
            StringBuilder total = new StringBuilder();
            // Wrap a BufferedReader around the InputStream
            BufferedReader rd = new BufferedReader(
                    new InputStreamReader(is));
            // Read response until the end
            try {
                while ((line = rd.readLine()) != null) {
                    total.append(line);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            // Return full string
            return total;
        }

    });

Is this correct which i have written?

how to write the Php for this?

  • 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-06-07T12:08:45+00:00Added an answer on June 7, 2026 at 12:08 pm

    use this

        JSONObject myjson=new JSONObject();
            myjson.put("userName", "someOne");
            myjson.put("password", "123");
    

    and StringEntity se = new StringEntity(myjson.toString());

    and httpPost.setEntity(se);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to find a way to send a POST HTTPS request from Python to
I am currently trying to find a way to handle USB data transfer on
I am trying to find a way, using AFNetworking, to set the Content-Type header
Hey I am trying to find a way to get my post records filtered.
I'm trying to create a way to have users comment on my posts. Currently
I'm currently trying to find the best way (in term of usability and performance)
Im trying to find a way to pull random images from either a post
Trying to find a way to remove blank pages from a document I wrote
I am trying to find a way to increment a second primary key column
I am trying to find a way to reverse a string, I've seen alternatives

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.