2016-02-18 2 views
1

Ниже приведен запрос POST со стандартным HttpWebRequest и HttpWebResponse. В основном это файл после binanry с некоторыми параметрами.Загрузить файл без Multipart/Form-Data с помощью RestSharp

Как я могу сделать то же самое с RestSharp?

Источник:

https://github.com/attdevsupport/ATT_APIPlatform_SampleApps/tree/master/RESTFul/SpeechCustom, ATT_APIPlatform_SampleApps/успокоительной/Речь/Csharp/app1 /]

HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(string.Empty+parEndPoint); 

httpRequest.Headers.Add("Authorization", "Bearer " + parAccessToken); 
httpRequest.Headers.Add("X-SpeechContext", parXspeechContext); 
if (!string.IsNullOrEmpty(parXArgs)) 
{ 
    httpRequest.Headers.Add("X-Arg", parXArgs); 
} 
string contentType = this.MapContentTypeFromExtension(Path.GetExtension(parSpeechFilePath)); 
httpRequest.ContentLength = binaryData.Length; 
httpRequest.ContentType = contentType; 
httpRequest.Accept = "application/json"; 
httpRequest.Method = "POST"; 
httpRequest.KeepAlive = true; 
httpRequest.SendChunked = parChunked; 
postStream = httpRequest.GetRequestStream(); 
postStream.Write(binaryData, 0, binaryData.Length); 
postStream.Close(); 

HttpWebResponse speechResponse = (HttpWebResponse)httpRequest.GetResponse(); 

ответ

3

Простой пример загрузки:

RestClient restClient = new RestClient("http://stackoverflow.com/"); 
    RestRequest restRequest = new RestRequest("/images"); 
    restRequest.RequestFormat = DataFormat.Json; 
    restRequest.Method = Method.POST; 
    restRequest.AddHeader("Authorization", "Authorization"); 
    restRequest.AddHeader("Content-Type", "multipart/form-data"); 
    restRequest.AddFile("content", imageFullPath); 
    var response = restClient.Execute(restRequest); 
+0

Как сделать то же самое без многоголосных ? Можете ли вы предложить такой же способ сделать в рубине? –