yhirose/cpp-httplib

how to download a file in android ?

liusj5257 opened this issue · 1 comments

I can use it to download a file in windows but android return something wrong.

    httplib::Client client(nation.cdnurl);
    client.load_ca_cert_store(kCert, sizeof(kCert));
    // https://blhxstatic.yo-star.com/android/resource/88da22d87437197be27b4b238cf38c2d
    auto res = client.Get("/android/resource/" + ABHash,
                          [&](const char* data, size_t data_length) {
                            file.write(data, data_length);
                            return true;
                          });
    file.close();
    if (res == nullptr) {
      LOGE("download failure, error is: %d", static_cast<int>(res.error()));
      std::cout << "download failure, error is: " << res.error();
      return false;
    }

android return

<?xml version=“1.0” encoding=“UTF-8”?> <Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>0KA7MW11KQFP5M7J</RequestId><HostId>h4mi47dW174GAs41bRxkPmY0xUGKBTsGcCq3M8EBZFVehN+jtZCvWO/DcAwsN6Cpr5MNef7BIMA=</HostId></Error>

@liusj5257 it seems like you don't have enough access right to get the resource.