Question

I Can not get my POCO C++ library to send a request on Android, it only throws an error since address can not be found, below is my code. Why does'nt it work? I've been using this as a reference and it's desired to function on both android and ios.

int NetPoco::getJson(string url){

try
  {
    printnet("Prepare session");

    // prepare session
    URI uri("www.google.se");
    HTTPClientSession session(uri.getHost(), uri.getPort());

    // prepare path
    printnet("Prepare path");

    string path(uri.getPathAndQuery());
    if (path.empty()) path = "/";

    // send request
    printnet("Prepare request for");
    printnet(path.c_str());
    HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
    session.sendRequest(req);

    // get response
    printnet("Get response");

    HTTPResponse res;
    cout << res.getStatus() << " " << res.getReason() << endl;

    // print response
    printnet("Print response");

    istream &is = session.receiveResponse(res);
    StreamCopier::copyStream(is, cout);
    printnet("RESULT");

  }
  catch (Exception &ex)
  {
    printnet(ex.displayText().c_str());
    //cerr << ex.displayText() << endl;
    return -1;
  }

  return 0;
}

When run on my Android device i get only:

04-11 15:33:30.492: D/NET_TAG(16118): Prepare session
04-11 15:33:30.492: D/NET_TAG(16118): Prepare path
04-11 15:33:30.492: D/NET_TAG(16118): Prepare request for
04-11 15:33:30.492: D/NET_TAG(16118): www.google.se
04-11 15:33:30.500: D/NET_TAG(16118): No address found
Was it helpful?

Solution

Using native Networking still needs your android manifest to be updated to allow network operations from the app:

<uses-permission android:name="android.permission.INTERNET" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top