6
My application in Android
picks up the String
sends to the arquivo.php
that processes the data.
I soon realized I couldn’t pass the code on base64
to the arquivo.php
.
I need some function in java
what compact long String
and send the same with a smaller size and that the arquivo.php
can unzip 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);
}
}
I just need to send all the contents of the page to
php
so that he can process only the data that I desire, I did not find a way to achieve this in theAndroid/Java
, pass multiple simultaneous requests containing the entire page would not generate a higher load? In my view yes, compacting the post would relieve more all this load. We are talking about more than 400 possible connections. Or would not need such a compression? Since the connection is fast, and the response also.– Florida
@Florida I try to create an example in java on android and send you
– Guilherme Nascimento
I tried not to use the
StandardCharsets
, tried in many ways, at first your code was not compatible with which the application is intended. 4.0 onwards.– Florida