I am behind the proxy and proxy will authentication. Because of that
, I am facing lots of problem for Downloading files from Web Server as well Uploading Files to Web Server. So, I decided to Install Web server in my Desktop itself, So that it's easy to test my Application. After installing Web server, I can open my Text File Using Following URL http://127.0.0.1/testData.txt Through Web Browser.
When I tried this URL to Download Text file from Android,I am getting “Connection refused”
Can you Help me to Solve this problem ,
Please.... .
I have attached my Coding here. (I have deleted proxy settings from emulator. )
Using java Syntax Highlighting
- import java.io.BufferedInputStream;
- import java.io.InputStream;
- import java.net.URL;
- import java.net.URLConnection;
- import org.apache.http.util.ByteArrayBuffer;
- import android.app.Activity;
- import android.os.Bundle;
- import android.widget.TextView;
- public class DownloadText extends Activity {
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- /* We will show the data we read in a TextView. */
- TextView tv = new TextView(this);
- /* Will be filled and displayed later. */
- String myString = null;
- try {
- /* Define the URL we want to load data from. */
- URL myURL = new URL("http://127.0.0.1/testData.txt");
- /* Open a connection to that URL. */
- URLConnection ucon = myURL.openConnection();
- /* Define InputStreams to read
- * from the URLConnection. */
- InputStream is = ucon.getInputStream();
- BufferedInputStream bis = new BufferedInputStream(is);
- /* Read bytes to the Buffer until
- * there is nothing more to read(-1). */
- ByteArrayBuffer baf = new ByteArrayBuffer(50);
- int current = 0;
- while((current = bis.read()) != -1){
- baf.append((byte)current);
- }
- /* Convert the Bytes read to a String. */
- myString = new String(baf.toByteArray());
- } catch (Exception e) {
- /* On any Error we want to display it. */
- myString = e.getMessage();
- }
- /* Show the String on the GUI. */
- tv.setText(myString);
- this.setContentView(tv);
- }
- }
Parsed in 0.037 seconds, using GeSHi 1.0.8.4
Regards,
Venkat.






