------ Solution ------
The issue was on our server. It can only handle post requests if we put www in front of our domain name. So that\'s what
Try sending your data as below:
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 60000); //1 min
HttpConnectionParams.setSoTimeout(httpParams, 60000); //1 min
HttpClient client = new DefaultHttpClient(httpParams);
HttpPost post = new HttpPost("http://myURL/uploadImage.php");
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("image", image_str));
post.setEntity(new UrlEncodedFormEntity(pairs, HTTP.UTF_8)); // as UTF-8
HttpResponse response = client.execute(post);
Have you tried reading the raw post data in PHP? Something like
$data = $xml = file_get_contents('php://input');
Have a look at this link for more info
http://www.codediesel.com/php/reading-raw-post-data-in-php/
just download the Base64.java http://iharder.sourceforge.net/current/java/base64/ & put that file in your project & then
just replace the
String image_str = Base64.encodeToString(byte_arr, Base64.DEFAULT);
this with
String image_str = Base64.encodeBytes(byte_arr);
replace this post.setEntity(new UrlEncodedFormEntity(pairs));
with
post.setEntity(new UrlEncodedFormEntity(pairs,HTTP.UTF_8));
Also check while importing the Base64 it will import file from your package & then post to server it will post.
in your php code just change
change this
$base = $_POST["image"];
to
$base = $_REQUEST['image'];
This is the code for image:
ByteArrayOutputStream bao = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, bao);
byte [] ba = bao.toByteArray();
String ba1=Base64.encodeBytes(ba);
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("image",ba1));
This is the HTTP code for sending the image to the server:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://servername.com/uploadimage.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
If you find any more difficulties ask me or a check:
In PHP header file changes :
header('Content-Type: image/jpg; charset=utf-8');
$base=$_REQUEST['image'];
Is the HTTP-Response-Code you are getting 200? If so, try setting these header-fields:
"Accept": "text/html"
"Accept-Language": "en"
"Content-Length": yourString.length
"Content-Type": "application/x-www-form-urlencoded"