当收到 MMS 消息并包含媒体(图像、视频)时,它确实会将计数放入NumMedia
针对您的服务器的 POST 请求的字段中。各个媒体 url 和标识符将附加它们的连续序列号(最多 10 个),这将导致 POST 请求具有许多单独的字段,每个字段用于媒体内容:
"MediaContentType0" : "",
"MediaUrl0" :"",
"MediaContentType1" : "",
"MediaUrl1" :""
在 POST 请求 (!=0 NumMedia
) 中检测到媒体后,您应该遍历字段以检索有趣的参数。
请参阅下面的示例实现:
// Build name value pairs for the incoming web hook from Twilio
NameValueCollection nvc = Request.Form;
// Type the name value pairs
string strFrom = nvc["From"];
string strNumMedia = nvc["NumMedia"];
string strBody = nvc["Body"];
// Holds the image type and link to the images
List<string> listMediaUrl = new List<string>();
List<string> listMediaType = new List<string>();
List<Stream> listImages = new List<
// Find if there was any multimedia content
if (int.Parse(strNumMedia) != 0) {
// If there was find out the media type and the image url so we can pick them up
for (int intCount = 0; intCount < int.Parse(strNumMedia);) {
// Store the media type for the image even through they should be the same
listMediaType.Add(nvc[("MediaContentType" + intCount).ToString()]);
// Store the image there is a fair chance of getting more then one image Twilio supports 10 in a single MMS up to 5Mb
listMediaUrl.Add(nvc[("MediaUrl" + intCount).ToString()]);
// Update the loop counter
intCount = intCount + 1;
}
}