如何与Android NDK http连接? [英] how to make http connection with android ndk?
问题描述
任何人可以帮助我使用的Android NDK创建HTTP连接?我想定义在C http连接/ C ++ code中的方法,并希望使用JNI从Java code调用它。
Can anybody help me to create http connection using android ndk?I want to define the methods for http connection in c/c++ code and want to call it from java code using jni.
下面code是SDK。
the below code is from sdk.
httpCon = (HttpURLConnection) httpUrl.openConnection();
httpCon.setRequestMethod("GET");
if (httpCon.getResponseCode() == HttpURLConnection.HTTP_OK)
{
is = httpCon.getInputStream();
int ch;
sb = new StringBuffer();
while ((ch = is.read()) != -1) {
sb.append((char) ch);
}
}
同样的事情,我想用NDK做的。
same thing i want to do with ndk.
推荐答案
有是Android系统级至少2.2和2.3版本提供了NDK,没有HTTP库。我看到3种可能的解决方案,为您的任务:
There is no HTTP library provided with NDK for Android system level, at least for 2.2 and 2.3 versions. I see 3 possible solutions for your task:
- 使用libcurl的移植为Android平台。
- 写在C或C ++根据您的要求而不是Linux插槽Android系统级你自己的HTTP库。
- 有很多已经被一些好心人写简单的(而不是简单)的HTTP库。您可以将它们的港口之一。
最后,你需要提供通过JNI从库的API来你的Java应用程序。希望这会有所帮助。
And finally you need to provide an API through JNI from the library to your Java application. Hope this will help.
这篇关于如何与Android NDK http连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!