【问题标题】:Poco C++ Net on Android does not find AddressAndroid 上的 Poco C++ Net 找不到地址
【发布时间】:2013-04-11 13:40:56
【问题描述】:

我无法让我的 POCO C++ 库在 Android 上发送请求,它只会抛出错误,因为找不到地址,下面是我的代码。为什么它不起作用?我一直在使用this 作为参考,希望它可以在 android 和 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;
}

在我的 Android 设备上运行时,我只得到:

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

【问题讨论】:

    标签: android android-ndk poco-libraries


    【解决方案1】:

    使用本机网络仍然需要更新您的 android 清单以允许从应用程序进行网络操作:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-11
      • 2017-07-20
      • 1970-01-01
      • 1970-01-01
      • 2013-05-21
      • 1970-01-01
      相关资源
      最近更新 更多