Unicode C++ Requires Chilkat v11.0.0+
Unicode C++
Send an MMS with Twilio using a media URL
See more Twilio Examples
Send an image and an optional caption from an MMS-capable Twilio number. Supply an MMS-supported destination in E.164 format and replace the example media URL with an HTTPS URL Twilio can fetch. The host must handle HEAD and GET and return the correct Content-Type for the file.
Live send. With live credentials and valid inputs, this request submits a billable message. Save the Message SID to check delivery later. Supported media types and size limits.
Chilkat Unicode C++ Downloads
#include <CkHttpW.h>
#include <CkStringBuilderW.h>
#include <CkHttpRequestW.h>
#include <CkHttpResponseW.h>
#include <CkJsonObjectW.h>
void ChilkatSample(void)
{
bool success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
CkHttpW http;
http.put_RequireSslCertVerify(true);
http.put_BasicAuth(true);
// Load the owning Account SID and an API key from application configuration.
const wchar_t *accountSid = L"YOUR_ACCOUNT_SID";
http.put_Login(L"YOUR_API_KEY_SID");
http.put_Password(L"YOUR_API_KEY_SECRET");
CkStringBuilderW url;
url.Append(L"https://api.twilio.com/2010-04-01/Accounts/");
url.Append(accountSid);
url.Append(L"/Messages.json");
// Add raw field values. Chilkat form-encodes them, including the + in a phone number.
CkHttpRequestW req;
req.put_HttpVerb(L"POST");
req.put_ContentType(L"application/x-www-form-urlencoded");
req.AddParam(L"From",L"YOUR_MMS_ENABLED_NUMBER");
req.AddParam(L"To",L"RECIPIENT_E164_NUMBER");
// Supply a URL for the file itself so Twilio can retrieve the media.
req.AddParam(L"MediaUrl",L"https://media.example.com/photo.jpg");
req.AddParam(L"Body",L"Photo attached.");
CkHttpResponseW resp;
CkJsonObjectW reply;
success = http.HttpReq(url.getAsString(),req,resp);
if (resp.get_StatusCode() == 0) {
wprintf(L"%s\n",http.lastErrorText());
return;
}
bool parsed = reply.Load(resp.bodyStr());
if ((success != true) || (resp.get_StatusCode() != 201)) {
wprintf(L"HTTP %d\n",resp.get_StatusCode());
if ((parsed == true) && (reply.HasMember(L"code") == true)) {
wprintf(L"Twilio error %d: %s\n",reply.IntOf(L"code"),reply.stringOf(L"message"));
}
return;
}
if (parsed != true) {
wprintf(L"Expected a JSON response.\n");
return;
}
if ((reply.JsonTypeOf(L"sid") != 1) || (reply.JsonTypeOf(L"status") != 1)) {
wprintf(L"The create response is missing the message SID or status.\n");
return;
}
wprintf(L"Message SID: %s\n",reply.stringOf(L"sid"));
wprintf(L"Initial status: %s\n",reply.stringOf(L"status"));
}