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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:03:00+00:00 2026-06-01T12:03:00+00:00

though the code is a little long, most of them are very simple IMO.

  • 0

though the code is a little long, most of them are very simple IMO. now im writing an android app that posts data to a website and displays the returned HTML code to the TextView.First i wrote a simple java POST method, it works perfect in my computer(on linux, post username and password to http://forum.xda-developers.com/login.php, and it returned the HTML successfully, though which prompts me that the username and password is incorrect):

package com.app.main;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;

public class Connection
{
    String returnText = "";                        
    String returnLine;

            //data which is about to be posted
    public String data = "vb_login_username=test&vb_login_password&securitytoken=guest&do=login";

    public String returnHTML()
    {
    try {
            URL url = new URL("http://forum.xda-developers.com/login.php");
            URLConnection conn = url.openConnection();
            conn.setDoOutput(true);
            OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
            wr.write(data);
            wr.flush();
            BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));

            while((returnLine = rd.readLine()) != null) {
                returnText += returnLine;
            }

            wr.close();
            rd.close();

            return returnText;

    } catch (Exception e) {
         return "ERROR: "+e.getMessage();
      }
    }
}

i tested the code using:

Connection net_start = new Connection();
System.out.println(net_start.returnHTML());

perfect. HTML returned successfully, then i go to write an android app, which is very simple, only having a button and an TextView on it. when i press the button, the TextView will display the returned HTML if successfully. Here is the source code of the main Activity.java

package com.app.main;

import android.app.Activity;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class AndroidTestActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final TextView displayResult = (TextView)findViewById(R.id.displayResult);
    Button login = (Button)findViewById(R.id.login);

    //set dispalyResult scrollable
    displayResult.setMovementMethod(new ScrollingMovementMethod());

    login.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            Connection net_start = new Connection();
            displayResult.setText(net_start.returnHTML());      

        }

    });

    }

}

very simple code, the only difference from that above is that i set the returned HTML display on the TextView instead of the command line. but i failed. According to debugging, i found the app throws an Exception at that line in Connection.java: OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());, the catched e said that: java.net.UnknownHostException: forum.xda-developers.com, but i indeed can login the xda-developers website on my cellphone(i debug the app using adb on my phone), what’s the matter with that? cannot android use URLConnection? any help appreciated 🙂

  • 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-01T12:03:01+00:00Added an answer on June 1, 2026 at 12:03 pm

    Is it available?

     <uses-permission 
            android:name="android.permission.INTERNET" />
    

    in your android application’s manifest file..

    Your code works fine in my case:

    The result of returnText is :

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en"><head><meta name="robots" content="noindex,follow" /><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><meta http-equiv="X-UA-Compatible" content="IE=9" ><meta name="keywords" content="XDA,MDA,Vario,HTC,Qtek,wallaby,wizard,tytn,hermes,alpine,prophet,i-mate,jam,dopod,tornado,typhoon,programming,coding,modding,wiki,forum,news,xdatools,xdaunlock,romkitchen,rom,development,lobster,unlock,imei" /><meta name="description" content="Android and Windows Mobile Developers - The Largest Community for Smartphone Hacks and Development of Apps" /><style type="text/css" id="vbulletin_css">/*** vBulletin 3.8.7 CSS* Style: 'XDA 2010'; Style ID: 16*/@import url("http://media.xda-developers.com/clientscript/vbulletin_css/style-e9bec9ef-00016.css");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code here is X++. I know very little about it, though I am
I would like to use GDB to step though the C++ code that makes
I need to write some code that would loop though all rows of a
I've been writing code, mostly proprietary, for a long time; spaghetti code and the
Let's say I have a javascript method that takes a little to long to
I'm going through a Fortran code, and one bit has me a little puzzled.
I have run though a code formatting tool to my c++ files. It is
I am looking though some source code from a third party and am repeatedly
Even though it is possible to write generic code in C using void pointer(generic
The following code seems not to work, even though the file appears to be

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.