如何将Android应用程序连接到Web应用程序((本地主机)) [英] How Can I Connect Android App To Web Application In ((Local Host ))

查看:123
本文介绍了如何将Android应用程序连接到Web应用程序((本地主机))的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个移动应用程序(android)来连接互联网和显示有关某些产品的信息。

当我在互联网上使用地址时喜欢http://Google.com它的工作原理

  ok  

但如果我将地址更改为http://localhost/mob1/Default.aspx它不起作用!!



java.net.ConnectException:无法连接到localhost /127.0.0.1(端口80):连接失败:ECONNREFUSED(拒绝连接)



由于某些原因我需要在本地主机上连接我的webSite。

有什么建议吗?



代码:

 受保护 < span class =code-sdkkeyword> String  ShowHtml()
{
// TextView myTxt =(TextView)findViewById(R.id.txtReturn);
HttpURLConnection urlConnection = null;
字符串 line = ;
尝试
{
网址myUrl =新网址( < span class =code-string> 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( 错误:,ex0.toString());

}
最后
{
如果(的URLConnection!= NULL){urlConnection.disconnect(); }


}
int Count = line.length();
return line = 计数:+String.valueOf(Count)+ / Start XML: + line;

}

解决方案

请使用http://10.0.2.2 iphost for localhost。

请使用此 http://10.0.2.2/ [ ^ ] localhost的IP地址


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

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 :

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;
		
	}

解决方案

Please use http://10.0.2.2 ip address for localhost.


Please user this http://10.0.2.2/[^] IP ADDRESS for localhost


这篇关于如何将Android应用程序连接到Web应用程序((本地主机))的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆