6
6
using System . Net ;
7
7
using System . Net . Http ;
8
8
using System . Net . Http . Headers ;
9
- using System . Text ;
10
9
using System . Threading . Tasks ;
11
10
12
11
namespace SubDBSharp
@@ -81,7 +80,7 @@ public Task<Response> DownloadSubtitle(string hash, params string[] languages)
81
80
public Task < Response > UploadSubtitle ( string subtitle , string movie )
82
81
{
83
82
var uriBuilder = new UriBuilder ( BaseAddress ) { Query = "action=upload" } ;
84
- Request request = BuildRequest ( uriBuilder . Uri , HttpMethod . Post , CreateFormContent ( subtitle , movie ) ) ;
83
+ Request request = BuildRequest ( uriBuilder . Uri , HttpMethod . Post , BuildFormContent ( subtitle , movie ) ) ;
85
84
return SendDataAsync ( request ) ;
86
85
}
87
86
@@ -137,29 +136,26 @@ protected virtual Request BuildRequest(Uri endPoint, HttpMethod method, HttpCont
137
136
return new Request ( endPoint , method , body ) ;
138
137
}
139
138
140
- private static HttpContent CreateFormContent ( string subtitle , string movie )
139
+ private static HttpContent BuildFormContent ( string subtitle , string movie )
141
140
{
142
- const string dispositionType = "form-data" ;
143
-
144
141
var content = new MultipartFormDataContent ( "xYzZY" ) ;
145
142
146
- // hash info
147
- StringContent stringContent = stringContent = new StringContent ( Utils . GetMovieHash ( movie ) ) ;
148
- stringContent . Headers . ContentDisposition = new ContentDispositionHeaderValue ( dispositionType )
143
+ // hash content
144
+ var stringContent = new StringContent ( Utils . GetMovieHash ( movie ) ) ;
145
+ stringContent . Headers . ContentDisposition = new ContentDispositionHeaderValue ( "form-data" )
149
146
{
147
+ DispositionType = "form-data" ,
150
148
Name = "\" hash\" "
151
149
} ;
152
150
153
- // subtitle file info
154
- FileStream fs = File . OpenRead ( subtitle ) ;
155
- var streamContent = new StreamContent ( fs ) ;
151
+ // subtitle content
152
+ var streamContent = new StreamContent ( File . OpenRead ( subtitle ) ) ;
156
153
streamContent . Headers . ContentType = new MediaTypeHeaderValue ( "application/octet-stream" ) ;
157
- var dispo = new ContentDispositionHeaderValue ( dispositionType )
154
+ streamContent . Headers . ContentDisposition = new ContentDispositionHeaderValue ( "form-data" )
158
155
{
159
156
Name = "\" file\" " ,
160
157
FileName = $ "\" { Path . GetFileName ( subtitle ) } \" "
161
158
} ;
162
- streamContent . Headers . ContentDisposition = dispo ;
163
159
164
160
// add contents to form
165
161
content . Add ( stringContent ) ;
@@ -170,9 +166,8 @@ private static HttpContent CreateFormContent(string subtitle, string movie)
170
166
171
167
public void Dispose ( )
172
168
{
173
- // will dispose _handler aswell (mentioned in contructor)
169
+ // calling dispose in _httClient handler will also dispose _httpClientHandler. (set in contructor)
174
170
_httpClient . Dispose ( ) ;
175
- //_httpClientHandler.Dispose();
176
171
}
177
172
}
178
173
}
0 commit comments