@@ -95,7 +95,7 @@ public static Optional<JsonElement> getJson(@NotNull String userAgent, @NotNull
95
95
*
96
96
* @return the response code of the request
97
97
*/
98
- public static int postJson (@ NotNull String userAgent , @ NotNull String urlString , @ NotNull JsonElement data , @ Nullable Consumer <HttpURLConnection > connectionConsumer ) {
98
+ public static int postJson (@ NotNull String userAgent , @ NotNull String urlString , @ Nullable JsonElement data , @ Nullable Consumer <HttpURLConnection > connectionConsumer ) {
99
99
int responseCode = -1 ;
100
100
HttpURLConnection connection = null ;
101
101
try {
@@ -105,7 +105,7 @@ public static int postJson(@NotNull String userAgent, @NotNull String urlString,
105
105
connection .setRequestProperty ("Content-Type" , "application/json" );
106
106
connection .setDoOutput (true );
107
107
if (connectionConsumer != null ) connectionConsumer .accept (connection );
108
- connection .getOutputStream ().write (data .toString ().getBytes ());
108
+ if ( data != null ) connection .getOutputStream ().write (data .toString ().getBytes ());
109
109
responseCode = connection .getResponseCode ();
110
110
} catch (final IOException e ) {
111
111
if (DEBUG ) e .printStackTrace ();
@@ -124,7 +124,7 @@ public static int postJson(@NotNull String userAgent, @NotNull String urlString,
124
124
*
125
125
* @return the response code of the request
126
126
*/
127
- public static int putJson (@ NotNull String userAgent , @ NotNull String urlString , @ NotNull JsonElement data , @ Nullable Consumer <HttpURLConnection > connectionConsumer ) {
127
+ public static int putJson (@ NotNull String userAgent , @ NotNull String urlString , @ Nullable JsonElement data , @ Nullable Consumer <HttpURLConnection > connectionConsumer ) {
128
128
int responseCode = -1 ;
129
129
HttpURLConnection connection = null ;
130
130
try {
@@ -134,7 +134,7 @@ public static int putJson(@NotNull String userAgent, @NotNull String urlString,
134
134
connection .setRequestProperty ("Content-Type" , "application/json" );
135
135
connection .setDoOutput (true );
136
136
if (connectionConsumer != null ) connectionConsumer .accept (connection );
137
- connection .getOutputStream ().write (data .toString ().getBytes ());
137
+ if ( data != null ) connection .getOutputStream ().write (data .toString ().getBytes ());
138
138
responseCode = connection .getResponseCode ();
139
139
} catch (final IOException e ) {
140
140
if (DEBUG ) e .printStackTrace ();
0 commit comments