My application in Android
gets the String
sends to the arquivo.php
that processes the data.
I soon saw that I could not pass the code in base64
to arquivo.php
.
I need some function in java
that compresses this long String
and sends it with a smaller size and that arquivo.php
can decompress it to its original state so I can manipulate the data.
Is there any way to do this? Reduce code by compressing it?
Follow the code I'm using.
public void postData(String html) {
URL url = null;
BufferedReader reader = null;
StringBuilder stringBuilder;
try {
url = new URL("http://192.168.0.15/android.php");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
Uri.Builder builder = new Uri.Builder()
.appendQueryParameter("par", html);
String query = builder.build().getEncodedQuery();
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(os, "UTF-8"));
writer.write(query);
writer.flush();
writer.close();
os.close();
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
stringBuilder = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
stringBuilder.append(line + "\n");
}
String output = stringBuilder.toString();
Log.d("httpcliente", "BUSCANDO => [" + output + "]");
} catch (IOException e) {
e.printStackTrace();
}
private class ParseURL extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... strings) {
StringBuffer buffer = new StringBuffer();
try {
Log.d("JSwa", "Connecting to ["+strings[0]+"]");
Document doc = Jsoup.connect(strings[0]).get();
Log.d("JSwa", "Connected to ["+strings[0]+"]");
// Get document (HTML page) title
String title = doc.title();
Log.d("JSwA", "Title ["+title+"]");
buffer.append("Title: " + title + "\r\n");
// Get meta info
Elements metaElems = doc.select("meta");
buffer.append("META DATA\r\n");
for (Element metaElem : metaElems) {
String name = metaElem.attr("name");
String content = metaElem.attr("content");
buffer.append("name ["+name+"] - content ["+content+"] \r\n");
}
Elements topicList = doc.select("h2.topic");
buffer.append("Topic list\r\n");
for (Element topic : topicList) {
String data = topic.text();
buffer.append("Data [" + data + "] \r\n");
}
postData(doc.html());
}
catch(Throwable t) {
t.printStackTrace();
}
return buffer.toString();
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
respText.setText(s);
}
}