您好想向用户的电话号码发送短信验证。我通过调用其余的 Api 在 ios 中完成了它,它可以工作。但是任何人都可以帮助我使用 android 我收到一个错误: code=401, message=UNAUTHORIZED。任何帮助将不胜感激?
url = https://{AccountSid}:{AuthToken}@api.twilio.com/2010-04-01/AccountsAccountSid}/SMS/Messages
private OkHttpClient mClient2 = new OkHttpClient();
Call post(String url, Callback callback) throws IOException {
Random rand = new Random();
randomNum = 1000 + rand.nextInt((100000 - 1000) + 1);
RequestBody formBody = new FormBody.Builder()
.add("To", etNumber.getText().toString())
.add("From", "+mynum")
.add("Body", "Your confirmation code for United taxi is" + randomNum)
.build();
Request request = new Request.Builder()
.url(url)
.post(formBody)
.build();
Call response = mClient2.newCall(request);
System.out.println(request.url());
response.enqueue(callback);
return response;
}
WWW-Authenticate 标头是:
WWW-Authenticate: Basic realm="Twilio API"