I have a problem to unzip a file received from server. I send a request, and server show me a text with code characters :S
With this code i receive a zip from server, but i need this text file unziped, and show in a EdText.
public void postLoginData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
"http://localhost:80/MOBILE/MBSERVER.V25?");
try {
String VENDED_VEN = "2", EMPRES_CFG = "1", VERSAO_CFG = "100", function = "GetMARCAS", REQUERY = null;
comando = (EditText) findViewById(R.id.comando);
// String PLS = comando.getText().toString();
List<NameValuePair> values = new ArrayList<NameValuePair>(6);
values = new ArrayList<NameValuePair>();
values.add(new BasicNameValuePair("EMPRES", EMPRES_CFG));
values.add(new BasicNameValuePair("USUARI", VENDED_VEN));
values.add(new BasicNameValuePair("VERSAO", VERSAO_CFG));
values.add(new BasicNameValuePair("ORIGEM", "AD"));
values.add(new BasicNameValuePair("FUNCAO", function));
values.add(new BasicNameValuePair("RQUERY", REQUERY));
httppost.setEntity(new UrlEncodedFormEntity(values));
// Execute HTTP Post Request
Log.w("LOG", "Execute HTTP Post Request");
HttpResponse response = httpclient.execute(httppost);
Log.w("LOG", "VALUES:"+values);
String str = inputStreamToString(response.getEntity().getContent())
.toString();
Log.w("LOG", str);
if (str.toString().equalsIgnoreCase("true")) {
Log.w("LOG", "TRUE");
result.setText("Login successful");
} else {
Log.w("LOG", "FALSE");
result.setText(str);
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private StringBuilder inputStreamToString(InputStream is) {
String line = "";
StringBuilder total = new StringBuilder();
// Wrap a BufferedReader around the InputStream
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
// Read response until the end
try {
while ((line = rd.readLine()) != null) {
total.append(line);
}
} catch (IOException e) {
e.printStackTrace();
}
// Return full string
return total;
}
@Override
public void onClick(View view) {
if (view == ok) {
postLoginData();
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…