embeddedRest icon indicating copy to clipboard operation
embeddedRest copied to clipboard

HTTPS, FTP and HTTP support

Open ElephantInTheRoomFirst opened this issue 9 years ago • 51 comments

Thanks for providing this library. I am looking for a library which can communicate with server using HTTPS, FTP and HTTP protocols on iOS and Android by REST calls. Currently cURL(https://ec.haxx.se/protocols.html) is promising candidate but it is kind of overweight.

I am not sure about protocols used by this library. It will be great if you provide more information(like current support and possibility of adding them) about following questions.

  1. Protocols
  2. Authentication
  3. SSL support. LibreSSL or OpenSSL etc.
  4. Possible problems to submit the app to app stores.

There is another low level library. I am not sure if you saw it before.

  • Asio C++ Library http://think-async.com/ https://github.com/chriskohlhoff/asio
  • https://github.com/cpp-netlib/cpp-netlib/projects
  • https://github.com/tghosgor/libashttp
  • https://github.com/vinniefalco/Beast/ Thanks in advance.

ElephantInTheRoomFirst avatar Jun 16 '17 23:06 ElephantInTheRoomFirst

I had already tried to use this lib for iOS and Android. Everything works fine on android but App Store rejects the app cause the lib doesn't support IPv6. The lib supports HTTP (not HTTPS) and has json interface for request body. Also I was trying to port curl to iOS and Android - this is a lot of pain. Also you can use boots::asio for url requests. I use C++ bindings for both iOS and Android. They are located here. This is a template project with C++ crossplatform framework 'Mitsoko'. Its core is located in a separate subrepo. You can make a rest request right in any presenter by including Mitsoko/Url/Request.hpp and writing a code:

using namespace Mitsoko::Url;
Request request;
request.method("POST");
request.body(json{
    { "name", "Sly Boogy" },
    { "age", 25 },
}.dump());
request.headers["Content-Type"] = "application/json";
request.performAsync([this](Response response, std::vector<char> data, Error error){
    if(response){
        if(response.statusCode() == 200){
            std::string dataString( data.begin(), data.end() );
            cout << "dataString = " << dataString << endl;
        }else{
            cout << "status code = " << response.statusCode() << endl;
        }
    }else{
        if(error){
            cout << "error = " << error.code() << " " << error.message() << endl;
        }else{
            cout << "undefined error" << endl;
        }
    }
});

Note: json is used from here

fnc12 avatar Jun 17 '17 06:06 fnc12

Thanks for the response. What is solution to make app accpeted in Apple app store? Yes, cURL is catch-all libraries. If possible, please go through lib links which I added. There is Beast(asio + C++) lib on github.

ElephantInTheRoomFirst avatar Jun 17 '17 06:06 ElephantInTheRoomFirst

The solution is simple: add IPv6 implementation. Or replace it with curl. You can find static curl both for x32 and x64 architectures for iOS. I don't see the reason to add IPv6 or SSL/TLS implementation here. More simple is to drop the lib and use either bindings or curl/asio

fnc12 avatar Jun 17 '17 06:06 fnc12

Thanks for the reply. I still thinking between asio and curl. Asio is good for future because native c++ as compared to curl. But the library is pretty low level. Another problem with asio is most of its wrappers bring another boost libraries which I do not like.

The JNI binding is already done.

In future, I should use user authentication to fetch data from server. Then I need HTTPS.

ElephantInTheRoomFirst avatar Jun 17 '17 19:06 ElephantInTheRoomFirst

Try Mitsoko project - this is a whole project with c++ bindings and java/objc helper classes for http(s) requests

fnc12 avatar Jun 18 '17 05:06 fnc12

Thanks. It is too late for it in current project. I shall try it in next project.

ElephantInTheRoomFirst avatar Jun 20 '17 07:06 ElephantInTheRoomFirst

Which networking library do you recommend for Mobile apps(Android and iOS)? I am looking at cURL and standalone asio. It will be great if recommend something.

ElephantInTheRoomFirst avatar Jun 22 '17 15:06 ElephantInTheRoomFirst

I recommend using c++ binding just like I use. Also I've used curl once. But it's not comfortable - I couldn't include it as sources. I added it as static lib both to iOS and Android. There was a lot of work: you have to add x32 and x64 static binaries to Xcode project and include headers for both architectures and switch them using #if. The can be located here. I don't remember exactly how I included curl to my android studio project but also must exist in different binaries for different architectures. Static libraries are hell cause there are about 7 active architectures for android and 2 for iOS. So I recommend using something architecture independent.

fnc12 avatar Jun 22 '17 16:06 fnc12

Thanks for advice. I am thinking to include curl or asio code in the project. It will be get compilied native library code, so it will reduce architecture problems.

The binding program find little complicated and late to use now. Do it have IPv6 problem also?

Unfortunately I do not have Mac computer now to verify correct library on both platforms.

ElephantInTheRoomFirst avatar Jun 22 '17 16:06 ElephantInTheRoomFirst

Bindings don't have IPv6 problem cause bindings use native classes: NSUrlConnection for iOS and HttpURLConnection for Android

fnc12 avatar Jun 23 '17 04:06 fnc12

hmm. I have native sychronous C++ library for all non UI(database and webserver) code. App calls lib and lib does not call app. How can I fit this Mitsoko and this libbrary. Are you calling app from Mitsoko binding?

ElephantInTheRoomFirst avatar Jun 23 '17 05:06 ElephantInTheRoomFirst

Did you try to abstract iOS and Android classes in C++ classes and try to program in C++?

ElephantInTheRoomFirst avatar Jun 23 '17 05:06 ElephantInTheRoomFirst

Yes I call app code (objc/swift and java) from mitsoko bindings. Mitsoko have modules in core. Every module has view and presenter. View has const void *handle member which stores a pointer to view controller/activity. You can find it here. java::lang::Object(handle) creates java object with JNI functions. sendMessage function calls java function within this object. You must specify a return type and function name. java::lang::Object(handle).sendMessage<void>("showProgress"); calls void showProgress() function in my activity. To do the same thing on iOS just write NS::Object(handle).sendMessage<void>("showProgress"); and it will call - (void)showProgress; function within your controller.

fnc12 avatar Jun 23 '17 05:06 fnc12

Yes I have abstract classes for HTTP requests, table/list views, routing and other stuff right in mitsoko. Check it out in mitsoko-template. This is a program with two pages (activities/view controllers). First page has a button. On touch it requests countries from server in JSON format, parses it and opens a new page with tableView/listView that shows that countries.

fnc12 avatar Jun 23 '17 05:06 fnc12

Interesting concept.

ElephantInTheRoomFirst avatar Jun 23 '17 06:06 ElephantInTheRoomFirst

How do you deal with HTTPS? As far as I know, iOS app must use HTTPS.

ElephantInTheRoomFirst avatar Jun 23 '17 07:06 ElephantInTheRoomFirst

No. iOS app can use HTTP without SSL. HTTPS works fine with bindings cause native classes deal with SSL.

fnc12 avatar Jun 23 '17 07:06 fnc12

https://techcrunch.com/2016/06/14/apple-will-require-https-connections-for-ios-apps-by-the-end-of-2016/ https://9to5mac.com/2016/06/15/ats-https-ios-apps/

ElephantInTheRoomFirst avatar Jun 23 '17 07:06 ElephantInTheRoomFirst

IDK. My several apps still work fine with HTTP

fnc12 avatar Jun 23 '17 07:06 fnc12

You are lucky. May be they do not know.

ElephantInTheRoomFirst avatar Jun 23 '17 07:06 ElephantInTheRoomFirst