17
17
import static java .net .HttpURLConnection .HTTP_MOVED_TEMP ;
18
18
19
19
/**
20
- * @see IHttpExecutor
21
- *
22
20
* @author GoodforGod
21
+ * @see IHttpExecutor
23
22
* @since 28.10.2018
24
23
*/
25
24
public class HttpExecutor implements IHttpExecutor {
@@ -30,7 +29,7 @@ public class HttpExecutor implements IHttpExecutor {
30
29
DEFAULT_HEADERS .put ("accept-language" , "en,ru;q=0.9" );
31
30
DEFAULT_HEADERS .put ("accept-encoding" , "gzip, deflate, br" );
32
31
DEFAULT_HEADERS .put ("user-agent" , "Mozilla/5.0 (Windows NT 10.0; WOW64) Chrome/68.0.3440.106" );
33
- DEFAULT_HEADERS .put ("cache-control " , "max-age=0 " );
32
+ DEFAULT_HEADERS .put ("content-Type " , "application/x-www-form-urlencoded " );
34
33
}
35
34
36
35
private final Map <String , String > headers ;
@@ -82,13 +81,14 @@ public String post(final String urlAsString, final String dataToPost) {
82
81
connection .setConnectTimeout (timeout );
83
82
headers .forEach (connection ::setRequestProperty );
84
83
85
- if (!BasicUtils .isEmpty (dataToPost )) {
86
- connection .setDoOutput (true );
87
- DataOutputStream wr = new DataOutputStream (connection .getOutputStream ());
88
- wr .writeBytes (dataToPost );
89
- wr .flush ();
90
- wr .close ();
91
- }
84
+ final String contentLength = (BasicUtils .isEmpty (dataToPost )) ? "0" : String .valueOf (dataToPost .length ());
85
+ connection .setRequestProperty ("Content-Length" , contentLength );
86
+
87
+ connection .setDoOutput (true );
88
+ DataOutputStream wr = new DataOutputStream (connection .getOutputStream ());
89
+ wr .writeBytes (dataToPost );
90
+ wr .flush ();
91
+ wr .close ();
92
92
93
93
final int status = connection .getResponseCode ();
94
94
if (status == HTTP_MOVED_TEMP || status == HTTP_MOVED_PERM ) {
0 commit comments