拥有下一个代码,使用resteasy获取twilio呼叫信息:
import java.util.Base64;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
import org.jboss.resteasy.client.jaxrs.ResteasyClient;
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
import com.twilio.rest.api.v2010.account.Call;
public class RestGetCallInfo1 {
public static void main(String[] args) {
try {
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget = client.target("https://api.twilio.com/2010-04-01/Accounts/AC99999999/Calls/CA77777777777.json");
String credentials = "AC99999999:888888888";
String base64encoded = Base64.getEncoder().encodeToString(credentials.getBytes());
Response response = target.request().header(HttpHeaders.AUTHORIZATION, "Basic " + base64encoded).get();
int status = response.getStatus();
if (status == 200) { //OK
Call call = response.readEntity(Call.class); //<------------- This fails!
System.out.println(call);
}
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
}
}
我想问你:
twilio-7.47.2-jar-with-dependencies.jar在内部使用了哪些“rest”库/工具(为了使用它而不是resteasy)?
如何正确获取json调用对象?用我得到的实际代码:
javax.ws.rs.processingexception:找不到内容类型为application/json且类型为class com.twilio.rest.api.v2010.account.call的messagebodyreader
编辑:我可以通过以下方式获得json格式的通话信息:
String call = response.readEntity(String.class);
暂无答案!
目前还没有任何答案,快来回答吧!