gpt4 book ai didi

java - 在Netbean中使用unirest发送短信

转载 作者:太空宇宙 更新时间:2023-11-04 10:35:43 28 4
gpt4 key购买 nike

我正在尝试使用uni-rest在java中发送短信。我遇到了一些错误。当我输入电话号码时,错误显示为NoClassDefFoundError:org/apache/http/HttpEntity以及一些我认为问题与jar文件有关的错误?下面是我编写的使用 uni-rest 发送短信的代码,所有库都附加在截图中,并且附加了错误快照。似乎 jar 文件没有添加到项目中。我做错了什么?

public class JavaApplication2 {


private static ObjectMapper objectMapper = new ObjectMapper();

public static void main(String[] args) throws UnirestException, IOException {
Scanner scanIn = new Scanner(System.in);
System.out.println("Enter your phone number: ");
String phoneNumber = scanIn.nextLine();
scanIn.close();
System.out.printf("entering to http response is ");

/*HttpResponse<String> response =
Unirest.post("xyz")
.header("authorization", "abc")
.header("content-type", "application/json")
.header("accept", "application/json")
.body("[{"
+ "'from': 'Example',"
+ "'to': '" +"435456"+ "',"
+ "'body': 'Hello World. This is a test message',"
+ "}]")
.asString();
*/

HttpResponse<String> response
=Unirest.post("http://xyz")
.header("authorization", "abc")
.header("content-type", "application/json")
.header("accept", "application/json")


.body({\"from\":\"InfoSMS\",\"to\":\"45465678\",\"text\":\"TestSMS.\"}")
.asString(
);



}
}

我使用了以下库 enter image description here

我收到以下错误

enter image description here

最佳答案

运行程序时,您需要将所需的 jar(包含 httpEntity 和其他相关类)添加到您的 classpath 中。构建路径用于编译/构建代码,但不用于执行。

关于java - 在Netbean中使用unirest发送短信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49507230/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com