Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi , i made a mobile application (android) to connect internet and Show informations about some products .
when i use adress on the internet Like http://Google.com it works
C#
ok
but if i change adress to http://localhost/mob1/Default.aspx it doesnt work !!

java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 80): connect failed: ECONNREFUSED (Connection refused)

for some reasons i need to connect my webSite in local Host .
any suggestion ?

Code :
Java
protected String ShowHtml()
	{
		//TextView myTxt=(TextView)findViewById(R.id.txtReturn); 
		HttpURLConnection urlConnection = null;
		String line="";
		try
		{
		URL myUrl=new URL("http://localhost/mob1/Default.aspx");
		urlConnection = (HttpURLConnection)myUrl.openConnection();
		BufferedReader in = new BufferedReader (new InputStreamReader(urlConnection.getInputStream()));
		

		while(in.readLine()!=null)
		{
			line=line+in.readLine().toString();
			//Counter++;
		}
	
	
		}
		catch(Exception ex0)
		{
		Log.d("Error : ",ex0.toString());

		}
		finally
		{
			if(urlConnection!=null){urlConnection.disconnect(); 	}
			
			
		}
		int Count=line.length();
		return line="Count: "+String.valueOf(Count)+"/ Start XML : "+line;
		
	}
Posted

Please use http://10.0.2.2 ip address for localhost.
 
Share this answer
 
v2
Please user this http://10.0.2.2/[^] IP ADDRESS for localhost
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900