Can RestSharp send binary data without using a multipart content type?

后端 未结 6 2290
闹比i
闹比i 2020-12-14 12:48

I have been using AddParameter to include XML bodies in my HTTP requests:

request.AddParameter(contentType, body, ParameterType.RequestBody);
         


        
6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 13:11

    In the latest version of RestSharp at the time of writing (version 104), the modification needs to be in Http.Sync.cs , method PreparePostData, which should read as:

        private void PreparePostData(HttpWebRequest webRequest)
        {
    
            // Multiple Files or 1 file and body and / or parameters
            if (Files.Count > 1 || (Files.Count == 1 && (HasBody || Parameters.Count>0)))
            {
                webRequest.ContentType = GetMultipartFormContentType();
                using (var requestStream = webRequest.GetRequestStream())
                {
                    WriteMultipartFormData(requestStream);
                }
            }
            else if (Files.Count == 1)
            {
                using (var requestStream = webRequest.GetRequestStream())
                {
                    Files[0].Writer(requestStream);
                }
            }
            PreparePostBody(webRequest);
        }
    

提交回复
热议问题