简体   繁体   English

curl无法连接到Android中的互联网

[英]curl fails to connect to the internet in Android

I have successfully built curl and a jni wrapper for it. 我已经成功地为它构建了curl和jni包装器。 However, when I execute the code in the emulator I get "Couldn't resolve host 'www.google.com'". 但是,当我在模拟器中执行代码时,我得到“无法解析主机'www.google.com'”。 If I provide the IP instead of a DNS name I get "couldn't connect to host". 如果我提供IP而不是DNS名称,我会“无法连接到主机”。 I am not behind a proxy so I have eliminated that possibility. 我不是代理人,所以我已经消除了这种可能性。

I am not sure if there is a setting in the emulator that I need to make to allow a native app to communicate with the internet. 我不确定模拟器中是否有设置允许本机应用程序与Internet通信。 Any help would be appreciated. 任何帮助,将不胜感激。 I have verified that connectivity to the internet exists via the adb shell. 我已经通过adb shell验证了与互联网的连接。

# nc -z -v www.google.com 80 #nc -z -v www.google.com 80
DNS fwd/rev mismatch: www.l.google.com != vw-in-f147.1e100.net DNS fwd / rev mismatch:www.l.google.com!= vw-in-f147.1e100.net
DNS fwd/rev mismatch: www.l.google.com != vw-in-f103.1e100.net DNS fwd / rev mismatch:www.l.google.com!= vw-in-f103.1e100.net
DNS fwd/rev mismatch: www.l.google.com != vw-in-f106.1e100.net DNS fwd / rev mismatch:www.l.google.com!= vw-in-f106.1e100.net
DNS fwd/rev mismatch: www.l.google.com != vw-in-f105.1e100.net DNS fwd / rev mismatch:www.l.google.com!= vw-in-f105.1e100.net
DNS fwd/rev mismatch: www.l.google.com != vw-in-f99.1e100.net DNS fwd / rev mismatch:www.l.google.com!= vw-in-f99.1e100.net
DNS fwd/rev mismatch: www.l.google.com != vw-in-f104.1e100.net DNS fwd / rev mismatch:www.l.google.com!= vw-in-f104.1e100.net
www.l.google.com [74.125.113.147] 80 (www) open www.l.google.com [74.125.113.147] 80(www)打开

Thanks. 谢谢。

I know that this is very late reply, but googling information on this is so difficult that I though I add my input for the future googlers. 我知道这是非常晚的回复,但谷歌的搜索信息是如此困难,我虽然我为未来的googlers添加了我的输入。

I have been working with the same problem and it seems that this is related to gethostbyname not working behind a proxy. 我一直在处理同样的问题,似乎这与gethostbyname无法在代理后面工作有关。 In the environment where there are no proxies things seem to work fine. 在没有代理的环境中,事情似乎工作得很好。 Also in my environment the proxy requires user name and password, so it may be even more difficult the get things working. 同样在我的环境中,代理需要用户名和密码,因此让事情变得更加困难可能更加困难。

I figured out that the application manifest was missing permission to access the internet. 我发现应用程序清单缺少访问Internet的权限。

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

I finally got this to work. 我终于开始工作了。 In case anyone is interested it seems like this issue is present only when the jni shared lib is statically linked to curl and other dependents. 如果有人感兴趣,似乎只有当jni共享库静态链接到curl和其他依赖项时才会出现此问题。 It works fine when the shared libs are loaded dynamically. 当动态加载共享库时,它工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM