我看了https://developers.facebook.com/docs/messenger-platform/send-messages/#file的Messenger文档,试图弄清楚如何发送本地附件。但是,当我使用httpclient尝试时,出现错误消息,消息正文不能为空,必须提供有效的附件或消息。下面是我的代码
string fileType = ImageExtensions.Contains(Path.GetExtension(url).ToUpper()) ? "image" : "file"; var multipartContent = new MultipartFormDataContent(); var content = new StringContent($"{{\"attachment\":{{\"type\":\"{fileType}\", \"payload\":{{\"is_reusable\"=true}}}}"); multipartContent.Add(new StringContent($"{{\"id\":\"{long.Parse(recipient)}\"}}"), "recipient"); multipartContent.Add(new StringContent($"{{\"attachment\":{{\"type\":\"{fileType}\", \"payload\":{{\"is_reusable\"=true}}}}"), "message"); var file1 = File.ReadAllBytes(url); var file2 = new ByteArrayContent(file1); file2.Headers.Add("Content-Type", GetMimeType(Path.GetExtension(url))); multipartContent.Add(file2,"filedata", Path.GetFileName(url)); request.Content = multipartContent;
文件类型是图像,而哑剧类型是图像/ jpeg。我知道URL存在,因为我检查了File.exists
我查看了https://developers.facebook.com/docs/messenger-platform/send-messages/#file上的Messenger文档,试图弄清楚如何发送本地附件。但是,当我尝试时...
欢迎使用堆栈溢出!