使用twilio-java 帮助程序库和您上面提到的文档中的以下代码:
然后我们实例化一个新的客户端对象,将请求方法设置为“POST”,在关联数组中填写“From”、“To”和“Url”参数,然后向 Twilio 发出请求!
除了您的 URL 的任何潜在问题...您是否还在控制台中配置您的 twilio 号码时将请求方法设置为 POST ?
import java.util.Map;
import java.util.HashMap;
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.instance.Account;
import com.twilio.sdk.resource.instance.Call;
import com.twilio.sdk.resource.factory.CallFactory;
public class MakeCall {
public static final String ACCOUNT_SID = "AC123";
public static final String AUTH_TOKEN = "456bef";
public static void main(String[] args) throws TwilioRestException {
TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
Account mainAccount = client.getAccount();
CallFactory callFactory = mainAccount.getCallFactory();
Map<String, String> callParams = new HashMap<String, String>();
callParams.put("To", "5105551212"); // Replace with your phone number
callParams.put("From", "(510) 555-1212"); // Replace with a Twilio number
callParams.put("Url", "http://demo.twilio.com/welcome/voice/"); // Configure your own URL with TwiML instructions using TwiML Bins
// Make the call
Call call = callFactory.create(callParams);
// Print the call SID (a 32 digit hex like CA123..)
System.out.println(call.getSid());
}
}