我已经配置了一个url来接收TwiML消息。 我收到以下字段
但是,我没有收到以下
虽然字段NumMedia的值为2,但我没有收到MediaUrl。
我用c#。
以下是我的类结构,它将保存从Twilio
收到的请求消息public class TwilioRequest
{
public string MessageSid { get; set; }
public string AccountSid { get; set; }
public string From { get; set; }
public string To { get; set; }
public string Body { get; set; }
public int NumMedia { get; set; }
public List<string> MediaContentType { get; set; }
public List<string> MediaUrl { get; set; }
}
请指导我。
答案 0 :(得分:1)
当收到MMS消息并包含媒体(图像,视频)时,它确实会将计数放入针对您服务器的POST请求的NumMedia
字段中。各个媒体网址和标识符将附加其连续的序列号(最多10个),这将导致POST请求具有许多单独的字段,每个字段用于媒体内容:
"MediaContentType0" : "",
"MediaUrl0" :"",
"MediaContentType1" : "",
"MediaUrl1" :""
在POST请求中检测到媒体时(!= 0 NumMedia
),您应该将字段迭代到retrieve interesting arguments。
请参阅以下示例实施:
// 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;
}
}