@@ -95,7 +95,7 @@ public static Optional<JsonElement> getJson(@NotNull String userAgent, @NotNull
9595 *
9696 * @return the response code of the request
9797 */
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 ) {
9999 int responseCode = -1 ;
100100 HttpURLConnection connection = null ;
101101 try {
@@ -105,7 +105,7 @@ public static int postJson(@NotNull String userAgent, @NotNull String urlString,
105105 connection .setRequestProperty ("Content-Type" , "application/json" );
106106 connection .setDoOutput (true );
107107 if (connectionConsumer != null ) connectionConsumer .accept (connection );
108- connection .getOutputStream ().write (data .toString ().getBytes ());
108+ if ( data != null ) connection .getOutputStream ().write (data .toString ().getBytes ());
109109 responseCode = connection .getResponseCode ();
110110 } catch (final IOException e ) {
111111 if (DEBUG ) e .printStackTrace ();
@@ -124,7 +124,7 @@ public static int postJson(@NotNull String userAgent, @NotNull String urlString,
124124 *
125125 * @return the response code of the request
126126 */
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 ) {
128128 int responseCode = -1 ;
129129 HttpURLConnection connection = null ;
130130 try {
@@ -134,7 +134,7 @@ public static int putJson(@NotNull String userAgent, @NotNull String urlString,
134134 connection .setRequestProperty ("Content-Type" , "application/json" );
135135 connection .setDoOutput (true );
136136 if (connectionConsumer != null ) connectionConsumer .accept (connection );
137- connection .getOutputStream ().write (data .toString ().getBytes ());
137+ if ( data != null ) connection .getOutputStream ().write (data .toString ().getBytes ());
138138 responseCode = connection .getResponseCode ();
139139 } catch (final IOException e ) {
140140 if (DEBUG ) e .printStackTrace ();
0 commit comments