I'm developing a app, this one send pictures from sd-card but now I need to send some parameters, how can I do this one?
// Open a HTTP connection to the URL
conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true); // Allow Inputs
conn.setDoOutput(true); // Allow Outputs
conn.setUseCaches(false); // Don't use a Cached Copy
conn.setRequestMethod("POST");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("ENCTYPE", "multipart/form-data");
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
conn.setRequestProperty("uploaded_file", fileName);
dos = new DataOutputStream(conn.getOutputStream());
dos.writeBytes(twoHyphens + boundary + lineEnd);
//dos.writeBytes (urlParameters);
dos.writeBytes("Content-Disposition: form-data; name=\"uploaded_file\";filename=\""
+ fileName + "\"" + lineEnd);
dos.writeBytes(lineEnd);
thanks a lot!
you can use MultiPartEntity with the help of it you can upload multiple files as well as parameters. this may help.
You can pass file and paramas in multipartentity like this :
public String reportCrime(String uploadFile, int userid, int crimetype,
String crimedetails, String lat, String longi, String reporteddate) {
String url;
MultipartEntity entity;
try {
url = String.format(Constant.SERVER_URL
+ "push_notification/reportCrime.php");
entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
//
File file = new File(uploadFile);
if (!file.equals("Image not Provided.")) {
if (file.exists()) {
Bitmap bmp = BitmapFactory.decodeFile(uploadFile);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bmp.compress(CompressFormat.JPEG, 70, bos);
InputStream in = new ByteArrayInputStream(bos.toByteArray());
ContentBody foto = new InputStreamBody(in, "image/jpeg", uploadFile);
entity.addPart("image", foto);
}
} else {
FormBodyPart image = new FormBodyPart("image", new StringBody(
""));
entity.addPart(image);
}
FormBodyPart userId = new FormBodyPart("userId", new StringBody(
String.valueOf(userid)));
entity.addPart(userId);
FormBodyPart crimeType = new FormBodyPart("crimetype",
new StringBody(String.valueOf(crimetype)));
entity.addPart(crimeType);
FormBodyPart crimeDetails = new FormBodyPart("crimedetail",
new StringBody(crimedetails));
entity.addPart(crimeDetails);
FormBodyPart latittude = new FormBodyPart("latittude",
new StringBody(lat));
entity.addPart(latittude);
FormBodyPart longitude = new FormBodyPart("longitude",
new StringBody(longi));
entity.addPart(longitude);
FormBodyPart reportedDate = new FormBodyPart("reporteddatetime",
new StringBody(reporteddate));
entity.addPart(reportedDate);
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
return "error";
}
HttpParams httpParams = new BasicHttpParams();
HttpContext httpContext = new BasicHttpContext();
HttpConnectionParams.setConnectionTimeout(httpParams, 10000);
HttpConnectionParams.setSoTimeout(httpParams, 10000);
try {
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(entity);
client = new DefaultHttpClient();
HttpResponse response = client.execute(httpPost);
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(response
.getEntity().getContent()));
StringBuffer sb = new StringBuffer();
String line = null;
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
result = sb.toString();
} finally {
if (in != null)
in.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
Related
I have this code which is able to upload a JPEG file to the server but the file is not recognized as JPEG. I think my problem is about encoding the JPEG file correctly. My solution is essentially the same as this one. I have tried other variants in appending the JPEG bytes using FileInputStream and using DataOutputStream instead of OutputStreamWriter, etc to no avail. Any suggestion appreciated.
final String boundary = "==================";
final String mimeType = "image/jpeg";
final int IMAGE_QUALITY = 100;
URL url = null;
HttpURLConnection urlConnection = null;
OutputStreamWriter request = null;
String response = null;
try {
url = new URL(params[0]);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true); ///
urlConnection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
urlConnection.setRequestMethod("POST");
OutputStream outputStream= urlConnection.getOutputStream();
request = new OutputStreamWriter(outputStream);
request.append("--" + boundary).append("\n");
request.append("Content-Disposition: form-data; name=\"file\"; filename=\"" + imageFileName + "\"").append("\n\n");
request.append("Content-Type: " + mimeType).append("\n\n");
request.append("Content-Encoding: base64").append("\n\n");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
imageThumbnail.compress(Bitmap.CompressFormat.JPEG, IMAGE_QUALITY, stream);
byte[] byteArray = stream.toByteArray();
//request.append(new String(byteArray)).append("\n");
String encodedImage = Base64.encodeToString(byteArray, Base64.DEFAULT);
request.append(encodedImage);
request.append("--" + boundary + "--");
request.flush();
request.close();
String line = null;
InputStreamReader isr = new InputStreamReader(urlConnection.getInputStream());
BufferedReader reader = new BufferedReader(isr);
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null) {
sb.append(line).append("\n");
}
response = sb.toString(); // = "Success"
isr.close();
reader.close();
} catch (MalformedURLException e) {
e.printStackTrace();
response = "Malformed URL";
} catch (IOException e) {
e.printStackTrace();
response = "IO Exception";
}
return response;
Thanks to this post here, solution is as follows:
final String boundary = "==================";
final String twoHyphens = "--";
final String crlf = "\r\n";
final String mimeType = "image/jpeg";
final int IMAGE_QUALITY = 100;
URL url = null;
HttpURLConnection urlConnection = null;
DataOutputStream dos;
String response = null;
try {
url = new URL(params[0]);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true); ///
urlConnection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
//urlConnection.setRequestProperty("Content-Type", "image/jpeg");
urlConnection.setRequestMethod("POST");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
imageThumbnail.compress(Bitmap.CompressFormat.JPEG, IMAGE_QUALITY, stream);
byte[] byteArray = stream.toByteArray();
dos = new DataOutputStream(urlConnection.getOutputStream());
dos.writeBytes(twoHyphens + boundary + crlf);
dos.writeBytes("Content-Disposition: form-data; name=\"file\"; filename=\"" + imageFileName + "\"" + crlf);
dos.writeBytes("Content-Type: " + mimeType + crlf);
dos.writeBytes(crlf);
dos.write(byteArray);
dos.writeBytes(crlf);
dos.writeBytes(twoHyphens + boundary + twoHyphens);
dos.flush();
dos.close();
String line = null;
InputStreamReader isr = new InputStreamReader(urlConnection.getInputStream());
BufferedReader reader = new BufferedReader(isr);
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null) {
sb.append(line).append("\n");
}
response = sb.toString();
isr.close();
reader.close();
} catch (MalformedURLException e) {
e.printStackTrace();
response = "Malformed URL";
} catch (IOException e) {
e.printStackTrace();
response = "IO Exception";
}
return response;
I have these inside the #Override protected String doInBackground(String... params) of an AsyncTask<String, Void, String>
I need to fetch data from this site http://www.speech.cs.cmu.edu/cgi-bin/tools/lmtool/run
But I am getting this "[ERRO] Problems with your corpus; cannot continue. Please check diagnostics [0 0]" When I am trying to send text file to site.
Here is my code:
String fileUrl = "/sdcard/fish.txt";
File logFileToUpload = new File(fileUrl);
final String BOUNDERY = "------WebKitFormBoundary4Pn8WfAaV8Bv3qqy";
final String CRLF = "\r\n";
// MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
StringBuilder sbBody_1 = new StringBuilder();
sbBody_1.append(BOUNDERY + CRLF);
sbBody_1.append("Content-Disposition: form-data; name=\"formtype\"" + CRLF);
sbBody_1.append(CRLF);
sbBody_1.append("simple");
sbBody_1.append(BOUNDERY + CRLF);
sbBody_1.append("Content-Disposition: form-data; name =\"corpus\""+"filename=\"fish\"" + CRLF);
//sbBody_1.append("Content-Disposition: form-data; filename=\"fish\"" + CRLF);
String str1="aaa";
sbBody_1.append(CRLF);
//sbBody_1.append(str1);
//sbBody_1.append(CRLF);
//sbBody_1.append(BOUNDERY + "--" );
StringBuilder sbBody_2 = new StringBuilder();
//sbBody_2.append("pratik");
sbBody_2.append(BOUNDERY + "--" );
URL url = new URL("http://www.speech.cs.cmu.edu/cgi-bin/tools/lmtool/run");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
// connection.addRequestProperty(reqEntity.getContentType().getName(), reqEntity.getContentType().getValue());
connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=----WebKitFormBoundary4Pn8WfAaV8Bv3qqy");
// connection.setChunkedStreamingMode(0);
OutputStream out = new BufferedOutputStream(connection.getOutputStream());
out.write(sbBody_1.toString().getBytes());
//byte[] bFile = new String(getBytesFromFile(Files1)).getBytes();
// System.out.println(""+bFile);
FileInputStream inputStreamToLogFile = new FileInputStream(logFileToUpload);
int bytesRead;
byte[] dataBuffer = new byte[1024];
while((bytesRead = inputStreamToLogFile.read(dataBuffer)) != -1) {
out.write(dataBuffer, 0, bytesRead);
System.out.println("output"+dataBuffer +bytesRead);
}
out.write(sbBody_2.toString().getBytes());
//out.write(CRLF.getBytes());
out.flush();
out.close();
BufferedReader bips = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String temp = null;
while ((temp = bips.readLine()) != null) {
System.out.println("output"+temp);
((TextView) findViewById(R.id.textview1))
.setText(temp);
}
bips.close();
connection.disconnect();
It's better to use OkHttp for network requests. You can try this example for multipart request.
Thank you for your help #MaxV i sloved my issue by using OkHttp and POSTMAN
Here is my code
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://www.hugosys.in/www.nett-torg.no/api/rpcs/uploadfiles/?");
File file = new File("/mnt/sdcard/xperia.png");
FileBody fileBody = new FileBody(file);
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("post_id", new StringBody("906"));
reqEntity.addPart("user_id", new StringBody("1"));
reqEntity.addPart("files", fileBody);
httpPost.setEntity(reqEntity);
response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
response_string =convertStreamToString(is);
..........
method to parse response
private static String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append((line + "\n"));
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
I m getting success from the server, but image is not received on server ... wht i m doing wrong
Apply this
private String doFileUpload()
{
ByteArrayOutputStream stream = new ByteArrayOutputStream();
myimage.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] imagebyte = stream.toByteArray();
System.out.println(imagebyte + "...................................");
String urlString = "your url";
try {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(urlString);
MultipartEntity reqEntity = new MultipartEntity();
Calendar cal = Calendar.getInstance();
String image_name = cal.getTime().toString();
image_name = image_name.replace(" ", "");
image_name = image_name.replace(":", "");
image_name = image_name.substring(3, 14);
//userfile
reqEntity.addPart("featured_img", new ByteArrayBody(imagebyte,
"Chasin_" + image_name + "_image.jpg"));
reqEntity.addPart("title", new StringBody(title_var));
reqEntity.addPart("description",new StringBody(description_var));
reqEntity.addPart("category",new StringBody(cat_var));
reqEntity.addPart("tags",new StringBody(tag));
reqEntity.addPart("userid",new StringBody(Constants.USER_ID));
post.setEntity(reqEntity);
HttpResponse response = client.execute(post);
HttpEntity resEntity = response.getEntity();
response_str = EntityUtils.toString(resEntity);
} catch (Exception ex) {
Log.e("Debug", "error: " + ex.getMessage(), ex);
}
return response_str;
}
Guys i think i have to work on these things
public void connectForMultipart() throws Exception {
con = (HttpURLConnection) ( new URL(url)).openConnection();
con.setRequestMethod("POST");
con.setDoInput(true);
con.setDoOutput(true);
con.setRequestProperty("Connection", "Keep-Alive");
con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
con.connect();
os = con.getOutputStream();
}
public void addFormPart(String paramName, String value) throws Exception {
writeParamData(paramName, value);
}
public void addFilePart(String paramName, String fileName, byte[] data) throws Exception {
os.write( (delimiter + boundary + "\r\n").getBytes());
os.write( ("Content-Disposition: form-data; name=\"" + paramName + "\"; filename=\"" + fileName + "\"\r\n" ).getBytes());
os.write( ("Content-Type: application/octet-stream\r\n" ).getBytes());
os.write( ("Content-Transfer-Encoding: binary\r\n" ).getBytes());
os.write("\r\n".getBytes());
os.write(data);
os.write("\r\n".getBytes());
}
public void finishMultipart() throws Exception {
os.write( (delimiter + boundary + delimiter + "\r\n").getBytes());
}
I have changed Content-Type: application/octet-stream\r\n" to Content-Type: image/jpeg\r\n\r\n and it worked :)
File imgFile = new File(Environment.getExternalStorageDirectory() + "/photo1/image2.jpg");
if (imgFile.exists()) {
myimage = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
// im.setImageBitmap(myimage);
}
This is the REST Api for uploading a document
Request URL
http:upload_url/{userid}/file
Method Type
POST
Header
Content-Type:application/json
Url Variables
1.{userid} - Unique id of the logged in user (e.g. VB000V)
form-data
{
key: "file",value: ,type: "file"
key: "filepath",value: "",type: "text"}
Code:
public class HttpUploadDoc extends AsyncTask<File, Void, String>{
private HttpClient client;
private HttpPost post;
private HttpResponse response;
private HttpEntity entity;
private ProgressDialog mProgressDialog;
private SharedPreferences sharedPreferences;
int serverResponseCode=0;
//for uploading..//
String end = "\r\n";
String twoHyphens = "--";
String boundary = "******";
private Context con;
StringBuffer buffer=new StringBuffer();
public HttpUploadDoc(Context con){
this.con=con;
}
#Override
protected void onPreExecute() {
mProgressDialog=new ProgressDialog(con);
mProgressDialog.setMessage("Loading");
mProgressDialog.show();
super.onPreExecute();
}
protected String doInBackground(File... params) {
File file=params[0];
String path=file.getAbsolutePath();
FileBody fileBody=new FileBody(file);
sharedPreferences=con.getSharedPreferences("LoginPref",Context.MODE_PRIVATE);
String userId=sharedPreferences.getString("userid", "");
client=new DefaultHttpClient();
try {
String filename=path.substring(path.lastIndexOf("/")+1);
URL url = new URL(AllRestApiUrls.UploadDocument+userId+"/file");
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setChunkedStreamingMode(128 * 1024);
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);
httpURLConnection.setUseCaches(false);
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setRequestProperty("Connection", "Keep-Alive");
httpURLConnection.setRequestProperty("ENCTYPE", "multipart/form-data");
httpURLConnection.setRequestProperty("Charset", "UTF-8");
httpURLConnection.setRequestProperty("Content-Type", "application/pdf");
httpURLConnection.setRequestProperty("Content-Type",
"multipart/form-data;boundary=" + boundary);
httpURLConnection.setRequestProperty("file",filename);
httpURLConnection.setRequestProperty("filepath", path);
DataOutputStream dos = new DataOutputStream(httpURLConnection.getOutputStream());
String formdata="key=\"file\", value=\""
+ filen+"\""+end
+"key=\"filepath\",value=\""+path+"\"";
dos.writeBytes(twoHyphens + boundary + end);
dos.writeBytes("Content-Disposition: form-data; "+formdata);
dos.writeBytes(end);
FileInputStream fis = new FileInputStream(path);
int bufferSize = 8 * 1024; // The size of the buffer, 8KB.
byte[] buffer = new byte[bufferSize];
int length = 0;
while ((length = fis.read(buffer)) != -1) {
// Write data to DataOutputStream
dos.write(buffer, 0, length);
}
dos.writeBytes(end);
dos.writeBytes(twoHyphens + boundary + twoHyphens + end);
fis.close(); // Close the FileInputStream.
dos.flush(); // Flush the data to DataOutputStream.
serverResponseCode = httpURLConnection.getResponseCode();
String serverResponseMessage = httpURLConnection.getResponseMessage();
Log.i("uploadFile", "HTTP Response is : "
+ serverResponseMessage + ": " + serverResponseCode);
entity.addPart("file", fileBody);
FileInputStream input=new FileInputStream(f.getPath());
entity.addPart("filepath", new StringBody(f.getAbsolutePath()));
post.setEntity(entity);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(f);
intent.setDataAndType(uri, "application/pdf");
con.startActivity(intent);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
mProgressDialog.dismiss();
return null;
}
}
This is my code.
I got Http 400 error, can someone help me?
HttpClient httpClient;
HttpPost httpPost;
HttpResponse response;
HttpContext localContext;
FileEntity tmp = null;
String ret = null;
httpClient = new DefaultHttpClient( );
httpClient.getParams().setParameter( ClientPNames.COOKIE_POLICY, CookiePolicy.RFC_2109) ;
httpPost = new HttpPost(url);
tmp = new FileEntity( data,"UTF-8" );
httpPost.setEntity( tmp );
httpPost.setHeader( "Content-Type", "multipart/form-data" );
httpPost.setHeader( "access_token", facebook.getAccessToken( ) );
httpPost.setHeader( "source", data.getAbsolutePath( ) );
httpPost.setHeader( "message", "Caption for the photo" );
localContext = new BasicHttpContext( );
response = httpClient.execute( httpPost,localContext );
bobince, thanks this is my new id, I will try put OAuth to my connection header.
And this is my old code, I will update it soon.
private void uploadPicture( ) throws ParseException, IOException {
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams( ).setParameter( CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1 );
HttpPost httppost = new HttpPost( "https://graph.facebook.com/me/photos" );
File file = new File( sdpicturePath );
// DEBUG
Log.d( "TSET", "FILE::" + file.exists( ) ); // IT IS NOT NULL
Log.d( "TEST", "AT:" + fbAccessToken ); // I GOT SOME ACCESS TOKEN
MultipartEntity mpEntity = new MultipartEntity( );
ContentBody cbFile = new FileBody( file, "image/png" );
ContentBody cbMessage = new StringBody( "TEST TSET" );
ContentBody cbAccessToken = new StringBody( fbAccessToken );
mpEntity.addPart( "access_token", cbAccessToken );
mpEntity.addPart( "source", cbFile );
mpEntity.addPart( "message", cbMessage );
httppost.setEntity( mpEntity );
// DEBUG
System.out.println( "executing request " + httppost.getRequestLine( ) );
HttpResponse response = httpclient.execute( httppost );
HttpEntity resEntity = response.getEntity( );
// DEBUG
System.out.println( response.getStatusLine( ) );
if (resEntity != null) {
System.out.println( EntityUtils.toString( resEntity ) );
} // end if
if (resEntity != null) {
resEntity.consumeContent( );
} // end if
httpclient.getConnectionManager( ).shutdown( );
} // end of uploadPicture( )
setEntity sets the source of the whole request body, so this would only work if the data file was an already-encoded multipart/form-data block.
To create a multipart/form-data-encoded form submission for use as a POST request body, you'll need a MIME multipart encoder, typically org.apache.http.entity.mime.MultipartEntity. Unfortunately, this is not bundled by Android so if you want it you'll have to pull in a newer HttpClient from Apache.
See this question for example code and this thread for background.
There is my working solution for sending image with post, using apache http libraries:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] imageBytes = baos.toByteArray();
HttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(StaticData.AMBAJE_SERVER_URL + StaticData.AMBAJE_ADD_AMBAJ_TO_GROUP);
String boundary = "-------------" + System.currentTimeMillis();
httpPost.setHeader("Content-type", "multipart/form-data; boundary="+boundary);
ByteArrayBody bab = new ByteArrayBody(imageBytes, "pic.png");
StringBody sbOwner = new StringBody(StaticData.loggedUserId, ContentType.TEXT_PLAIN);
StringBody sbGroup = new StringBody("group", ContentType.TEXT_PLAIN);
HttpEntity entity = MultipartEntityBuilder.create()
.setMode(HttpMultipartMode.BROWSER_COMPATIBLE)
.setBoundary(boundary)
.addPart("group", sbGroup)
.addPart("owner", sbOwner)
.addPart("image", bab)
.build();
httpPost.setEntity(entity);
try {
HttpResponse response = httpclient.execute(httpPost);
...then reading response
as for facebook graph api, this code works perfect.
however, sometimes, you need to use name instead of filename, graph api seems to conflict with rfc document.
final String BOUNDERY = "3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f";
final String CRLF = "\r\n";
StringBuilder sbBody_1 = new StringBuilder();
sbBody_1.append("--" + BOUNDERY + CRLF);
sbBody_1.append("Content-Disposition: form-data; filename=\"source\"" + CRLF);
sbBody_1.append(CRLF);
StringBuilder sbBody_2 = new StringBuilder();
sbBody_2.append(CRLF + "--" + BOUNDERY + "--");
URL url = new URL("https://graph.facebook.com/me/photos?access_token=" + accessToken);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDERY);
connection.setChunkedStreamingMode(0);
OutputStream out = new BufferedOutputStream(connection.getOutputStream());
out.write(sbBody_1.toString().getBytes());
out.write(bFile);// bFile is byte array of the bitmap
out.write(sbBody_2.toString().getBytes());
out.close();
BufferedReader bips = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String temp = null;
while ((temp = bips.readLine()) != null) {
Log.d("fbnb", temp);
}
bips.close();
connection.disconnect();