开发者

how to make http connection with android ndk?

Can anybody help me to create http connectio开发者_如何学编程n 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.

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

same thing i want to do with ndk.


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:

  1. Use the ported libcurl for Android platform.
  2. Write your own HTTP library for Android system level in C or C++ over linux sockets based on your requirements.
  3. There are lot of simple (and not simple) HTTP libraries already written by some good people. You can port one of them.

And finally you need to provide an API through JNI from the library to your Java application. Hope this will help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜