Skip to content
This repository was archived by the owner on Jan 31, 2022. It is now read-only.

Commit bef90f6

Browse files
Clément Le ProvostPLNech
authored andcommitted
Remove any dependency to Apache HTTP client (#91)
We are already using a plain `HttpURLConnection`, but the handling of POST request bodies was still done using Apache’s classes. This commit switches to plain built-in classes.
1 parent 2d2a635 commit bef90f6

File tree

1 file changed

+5
-7
lines changed
  • algoliasearch/src/main/java/com/algolia/search/saas

1 file changed

+5
-7
lines changed

algoliasearch/src/main/java/com/algolia/search/saas/Client.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
import android.os.Looper;
3030
import android.support.annotation.NonNull;
3131

32-
import org.apache.http.entity.StringEntity;
33-
import org.apache.http.message.BasicHeader;
34-
import org.apache.http.protocol.HTTP;
3532
import org.json.JSONArray;
3633
import org.json.JSONException;
3734
import org.json.JSONObject;
@@ -41,6 +38,7 @@
4138
import java.io.IOException;
4239
import java.io.InputStream;
4340
import java.io.InputStreamReader;
41+
import java.io.OutputStreamWriter;
4442
import java.io.UnsupportedEncodingException;
4543
import java.net.HttpURLConnection;
4644
import java.net.URL;
@@ -686,11 +684,11 @@ private byte[] _requestRaw(Method m, String url, String json, List<String> hosts
686684
if (!(requestMethod.equals("PUT") || requestMethod.equals("POST"))) {
687685
throw new IllegalArgumentException("Method " + m + " cannot enclose entity");
688686
}
689-
hostConnection.setRequestProperty("Content-type", "application/json");
687+
hostConnection.setRequestProperty("Content-type", "application/json; charset=UTF-8");
690688
hostConnection.setDoOutput(true);
691-
StringEntity se = new StringEntity(json, "UTF-8");
692-
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
693-
se.writeTo(hostConnection.getOutputStream());
689+
OutputStreamWriter writer = new OutputStreamWriter(hostConnection.getOutputStream(), "UTF-8");
690+
writer.write(json);
691+
writer.close();
694692
}
695693

696694
// read response

0 commit comments

Comments
 (0)