如何通过c#将Mime类型附件发送到REST API

时间:2016-08-30 14:13:58

标签: c# rest curl

我必须向REST API发送MIME类型附件,我们正在解决它的问题。我已经要求API支持他们根据curl请求建议解决方案请在下面找到curl请求

curl -ki -X POST -v -F auth_info='{"login":"02781","password":"joiuuV2r","domain":"68.146.98.31", "session_id":null}' -F params='{"i_menu":1573,"transition_info":{"event":"4","action":"Transfer","target_i_menu":1573,"destination":"200","play_prompt":"Y","prompt":"ZZZ.mp3"}}' -F upload_file="@/tmp/ringtone.mp3;type=audio/mpeg" https://posturl

我没有收到此代码,但我尝试发送MIME类型附件,如

     string fileName = file.FileName;// "menu.au";
     byte[] byteFiles = new byte[file.ContentLength];
     file.InputStream.Read(byteFiles, 0, file.ContentLength);
     using (HttpContent fileContent = new ByteArrayContent(byteFiles, 0, byteFiles.Length))
          {
               string mimeType = System.Web.MimeMapping.GetMimeMapping(fileName);

                                    //specifying MIME Type
               fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse(mimeType);

               content.Add(fileContent, "upload_file", fileName);
               var result = client.PostAsync(postUrl, content).Result;
          }

此请求获得响应200成功,但文件未上传。 请建议我任何解决方案。谢谢。

0 个答案:

没有答案