package citySlikkersV1.HttpClass;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import citySlikkersV1.ComManager.ComManager;
import android.app.Activity;
import android.util.Log;
public class HTTP_Request extends Activity {
private String url;
private UrlEncodedFormEntity mEntity;
private String response;
public HTTP_Request() {
this.url = null;
this.mEntity = null;
this.response = null;
}
public void go(String url,UrlEncodedFormEntity sendEntity){
InputStream inStream = null;
try {
HttpPost postMethod = new HttpPost (url);
HttpClient client = new DefaultHttpClient();
postMethod.setEntity(sendEntity);
final HttpParams params = client.getParams();
HttpConnectionParams.setConnectionTimeout(params, 6000);
HttpResponse httpResponse = client.execute(postMethod);
HttpEntity resEntity = httpResponse.getEntity();
inStream = resEntity.getContent();
ByteArrayOutputStream byteArrayOutputStream = new
ByteArrayOutputStream();
int byteCount = -1;
byte[] byteBuff = new byte[8196];
while ((byteCount = inStream.read(byteBuff, 0,
byteBuff.length)) != -1) {
byteArrayOutputStream.write(byteBuff, 0,
byteCount);
}
response = byteArrayOutputStream.toString();
} catch (Exception e) {
response = "<error>Error unzipping zipped content.</
errro>";
} finally {
try{
if (inStream != null) inStream.close();
if(inStream==null){
ComManager.getInstance
().UserPositionUpdates();
}
// very important
} catch (Exception e) {
/* Do nothing with this error */ }
}
}
public String getResponse() {
return this.response;
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en