将HttpPostedFileBase发布到远程Web API

时间:2017-09-09 05:03:08

标签: c# asp.net asp.net-mvc asp.net-web-api

我试图将HttpPostedFileBase发布到远程webApi。

public bool CreateClaimAttachmentCustomerDoc(ClaimAttachmentSimple attachment, HttpPostedFileBase hpf)
{    
            string jsonStrAttchment = JsonConvert.SerializeObject(attachment);
            string jsonHpf = JsonConvert.SerializeObject(hpf);

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(
                ConfigurationManager.AppSettings["ApiBaseUrl"] + "claim/CreateClaimAttachmentCustomerDoc?attachment=" + jsonStrAttchment + "&hpf=" + jsonHpf);
            request.Method = "POST";
            request.ContentType = "application/json";

            WebResponse webResponse = request.GetResponse();
            using (Stream webStream = webResponse.GetResponseStream())
            {
                if (webStream != null)
                {
                    using (StreamReader responseReader = new StreamReader(webStream))
                    {
                        responseReader.ReadToEnd();
                        return true;
                    }
                }
            }

            return false;
        }

收到以下错误。

  

Newtonsoft.Json.JsonSerializationException:'从中获取值时出错   ' ReadTimeout' on' System.Web.HttpInputStream'。'   InvalidOperationException:此流不支持超时。

0 个答案:

没有答案