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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:13:43+00:00 2026-05-31T07:13:43+00:00

I have this code, who should connect to a php remote file and should

  • 0

I have this code, who should connect to a php remote file and should get a String representing a XML file. But something is wrong, it is giving me error 401.

The variable url is the direction of the php:

String response=getXML("http://ficticiousweb.com/scripts/getMagazinesList.php");

If i paste the real direction (that is a ficticious direction) on the webbrowser, it works and gives me the XML.

This is my code:

public String getXML(String url){
    try{
        StringBuilder builder = new StringBuilder();
        HttpClient httpclient = new DefaultHttpClient();
        HttpGet httpget = new HttpGet(url);
        HttpResponse response = httpclient.execute(httpget);
        int statuscode = response.getStatusLine().getStatusCode();
        if(statuscode == 200)
        {
            HttpEntity entity = response.getEntity();
            InputStream content = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(content));
            String line;
            while ((line = reader.readLine()) != null)  builder.append(line);               
        }
        else throw new Exception("HTTP error: " + String.valueOf(statuscode));
        return builder.toString();
    }catch(Exception e){e.printStackTrace();}
    return null;
}

What is wrong with the code?

thanks

  • 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-31T07:13:44+00:00Added an answer on May 31, 2026 at 7:13 am

    You need to login to the requested site in order to download or access the xml. This can be done by authenticated schema based upon what is supported. Normally, there are 2 types of schemas where used. Basic and Digest. Below code will help you for BASIC AUTH.

    HttpClient httpclient = new DefaultHttpClient();
        HttpResponse response;
        String _username = "username";
        String _password = "password";
        try {
             ((AbstractHttpClient) httpclient).getCredentialsProvider().setCredentials(
                    new org.apache.http.auth.AuthScope(webhostname, webport)),
                    new org.apache.http.auth.UsernamePasswordCredentials(_username, _password));
    
            response = httpclient.execute(new HttpGet(completeurlhere));
            StatusLine statusLine = response.getStatusLine();
            if(statusLine.getStatusCode() == HttpStatus.SC_OK) {
                try {
                    InputStream is = response.getEntity().getContent();
                    this._data = is;
    
                } catch(Exception ex) {
                    Log.e("DBF Error",ex.toString());
                }                
            } else {
                response.getEntity().getContent().close();
                throw new IOException(statusLine.getReasonPhrase());
            }
        } catch(ClientProtocolException cpe) {
            Log.e("ClientProtocolException @ at FPT",cpe.toString());
        } catch(Exception ex) {
            Log.e("Exception at FETCHPROJECTASK",ex.toString());
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code <?php session_start(); if (isset($_GET[cmd])) $cmd = $_GET[cmd]; else die(You should
I have a friend who has code like this in his wordpress files: Blockquote
I have this code, which works fine, but I would like to be able
The title explains all... I have this snippet of code in my application: String
I have been working on this code but I can't find out what is
I have this code, to get followers and friends(peeps you are following), However I'm
Hello I have this snippet of jQuery code jQuery(document).ready(function($) { $.get(<?echo $site['url'];?>modules/tuitting/tuitting_core/classes/count.php, function (data)
I have this code in jQuery, that I want to reimplement with the prototype
I have this code: chars = #some list try: indx = chars.index(chars) except ValueError:
I have this code that performs an ajax call and loads the results into

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.