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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:56:09+00:00 2026-06-09T06:56:09+00:00

I am having one private web-services in which i need to pass authentication and

  • 0

I am having one private web-services in which i need to pass authentication and a JSONObject Request also.
The Authentication goes perfect and the Response is also OK but in response I am getting HTML Page Source code of the particular web-services implementation page.

Is their any problem with the JSONObject Request that i sent.

Please refer the code below:

public JSONObject getJSONFromUrl(String url)
{
try{
DefaultHttpClient httpClient=new DefaultHttpClient();

        HttpPost httppost=new HttpPost(url);
        httppost.setHeader("Authorization", "Basic "+Base64.encodeToString("abc:xyz".getBytes(), Base64.NO_WRAP));

         //Posting request on htt
          httppost.setHeader( "Content-Type", "application/json" );        
          httppost.setHeader("Accept","application/json");
            JSONObject jsonPara = new JSONObject();     
            jsonPara.put("password", "abc");
            jsonPara.put("username", "abc");




            JSONObject jsonobj=new JSONObject();

            jsonobj.put("request", "syncdata/get_country");
            jsonobj.put("para",jsonPara);

            Log.i("jason Object", jsonobj.toString());

            StringEntity se2 = new StringEntity(jsonobj.toString());

            se2.setContentEncoding("UTF-8");
            se2.setContentType("application/json");

            httppost.setEntity(se2);  
        HttpResponse httpResponse=httpClient.execute(httppost);
        HttpEntity httpEntity=httpResponse.getEntity();
        is=httpEntity.getContent();
    }
    catch(UnsupportedEncodingException ae)
    {
    ae.printStackTrace();           
    }
    catch(ClientProtocolException ae)
    {
        ae.printStackTrace();
    }
    catch(IOException ae)
    {
        ae.printStackTrace();
    }
    catch(JSONException e)
    {
        e.printStackTrace();
    }

    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();
        json =sb.toString();
    }
    catch(Exception ae)
    {
        ae.printStackTrace();
    }

    try
    {
        jObj=new JSONObject(json);
    }
    catch(JSONException e)
    {
    e.printStackTrace();    
    }

    return jObj;
}

Also how can i confirm that the response that I am getting is JSON or some other format (other then debugging) and am i getting the correct response which i actually should get.

  • 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-09T06:56:11+00:00Added an answer on June 9, 2026 at 6:56 am

    Refer this Code.

    I hope it will helpful to you…

    MainActivity.java

        public class MainActivity extends Activity {
    
    InputStream is=null;
    String result=null;
    String line=null;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    try
    {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://10.0.2.2/text.php");
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity entity = response.getEntity();
    is = entity.getContent();
    Log.e("Pass 1", "connection success ");
    }
    catch(Exception e)
    {
    Log.e("Fail 1", e.toString());
    Toast.makeText(getApplicationContext(), "Invalid IP Address",Toast.LENGTH_LONG).show();
    }    
    
    try
    {
    BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
    StringBuilder sb = new StringBuilder();
    while ((line = reader.readLine()) != null)
    {
    sb.append(line + "\n");
    }
    is.close();
    result = sb.toString();
    Log.e("Pass 2", "connection success ");
    }
    catch(Exception e)
    {
    Log.e("Fail 2", e.toString());
    }    
    
    try
    {
    JSONArray JA=new JSONArray(result);
    JSONObject json= null;
    final String[] str1 = new String[JA.length()];       
    for(int i=0;i<JA.length();i++)
    {
    json=JA.getJSONObject(i);
    str1[i]=json.getString("name");
    }
    
    final AutoCompleteTextView text = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
    final List<String> list = new ArrayList<String>();
    
    for(int i=0;i<str1.length;i++)
    {
    list.add(str1[i]);
    }
    
    Collections.sort(list);
    
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getApplicationContext(),
                    android.R.layout.simple_spinner_item, list);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    text.setThreshold(1);
    text.setAdapter(dataAdapter);
    
    text.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
    // TODO Auto-generated method stub
    Toast.makeText(getBaseContext(), list.get(arg2).toString(), Toast.LENGTH_SHORT).show();
    }
    });
    
    }
    catch(Exception e)
    {
    Log.e("Fail 3", e.toString());
    }
    }
    

    text.php

    <?php
    $host='127.0.0.1';
    $uname='root';
    $pwd='password';
    $db='android';
    $con = mysql_connect($host,$uname,$pwd) or die("connection failed");
    mysql_select_db($db,$con) or die("db selection failed");
    $r=mysql_query("select * from class",$con);
    while($row=mysql_fetch_array($r))
    {
    $cls[]=$row;
    }
    print(json_encode($cls));
    mysql_close($con);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having one Gtk+ and C application in which i want to set
I am having one hell of a time coming up with a decent way
I am having one heck of a hard time trying to figure this out.
I am having one problem with the PHP json_encode function. It encodes numbers as
I'm having one hell of a time trying to get my databinding to work
I'm having one doubt about the VIM ENCRYPTION key . I having a text
I am having one GtkVbox and I am adding it to GtkViewPort . View
I am having one flow field manager added on screen & in that manager
hi forum member I am having one problem with setting the radiofield in the
I've run into problems on numerous occasions of users not having one of the

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.