我正在尝试使用HTTPPOST上传图像和一些数据以及android中的图像,但我得到404响应代码。我正在尝试使用nameValuedPair()发送数据。请帮我。请检查我编写的以下代码以上传图像。
public void postImageToServer(Bitmap bitmap)
{
ByteArrayOutputStream stream=new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, stream);
byte[] byte_arr=stream.toByteArray();
String image_str=Base64.encodeToString(byte_arr, Base64.NO_WRAP|Base64.URL_SAFE);
ArrayList<NameValuePair> nameValuePairs=new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("source","android"));
nameValuePairs.add(new BasicNameValuePair("source_version","1.0.1"));
nameValuePairs.add(new BasicNameValuePair("venue_name","Soda Bars"));
nameValuePairs.add(new BasicNameValuePair("artist_name","Led Zepplin"));
nameValuePairs.add(new BasicNameValuePair("photo", image_str));
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
UrlEncodedFormEntity entity=new UrlEncodedFormEntity(nameValuePairs, "UTF-8");
httppost.setEntity(entity);
/* ResponseHandler<String> handler = new BasicResponseHandler();
String content = httpclient.execute(httppost, handler);*/
HttpResponse response=httpclient.execute(httppost);
//HttpResponse response = httpclient.execute(httppost);
System.out.println("response "+response.getStatusLine().getStatusCode());
String the_string_response = convertResponseToString(response);
System.out.println("response content "+the_string_response);
}catch(Exception e){
System.out.println("Error in http connection "+e.toString());
}
}