首页 > 解决方案 > 编译时没有 Ljava/nio/charset/Charset 类型的静态字段 DEF_CONTENT_CHARSET;在 Lorg/apache/http/protocol/HTTP 类中;

问题描述

使用 nexmo api 3.0+ 版本(不使用 4.0+ 因为需要 android 版本 8 api 27 )和 android 版本 6 api 23

我无法发送短信,因为它总是给出上述错误:没有 Ljava/nio/charset/Charset 类型的静态字段 DEF_CONTENT_CHARSET;在 Lorg/apache/http/protocol/HTTP 类中;

发送短信代码:

    AuthMethod auth = new TokenAuthMethod(APIKey, APISecret);
    NexmoClient client = new NexmoClient(auth);

    TextMessage message = new TextMessage(fromRecipient, toRecipient, messageContent);

    SmsSubmissionResult[] response = client.getSmsClient().submitMessage(message);

    for (SmsSubmissionResult responseMessage : response) {
        System.out.println(responseMessage);
    }

我导入了以下内容:

implementation 'org.apache.httpcomponents:httpclient:4.5+'

implementation 'org.apache.httpcomponents:httpcore:4.4+'

但它仍在查看旧的 httpclient 而不是导入的

有没有办法强制使用导入的 http 客户端/核心库而不是旧库?

标签: javaandroidandroid-studiohttpclientnexmo

解决方案


看起来您正在尝试将 Nexmo Java Server SDK 与 Android 一起使用。这不是受支持的,因为它需要在应用程序中存储诸如机密和私钥之类的东西。

推荐的方法是在某处的服务器上使用服务器 SDK 来保护这些信息,然后使用您自己的身份验证方案通过 Android 应用程序与其通信。


推荐阅读