Android 安卓上传图片

Android 安卓上传图片,android,http,web,http-status-code-404,Android,Http,Web,Http Status Code 404,我正试图用HTTPPOST在android中上传一张图片和一些数据,但我得到了404响应代码。我正在尝试使用nameValuedPair()发送数据。请帮帮我。请检查下面的代码,我已经写了上传图像 public void postImageToServer(Bitmap bitmap) { ByteArrayOutputStream stream=new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.

我正试图用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());
      }
}
public void postmagetoserver(位图)
{
ByteArrayOutputStream=新建ByteArrayOutputStream();
压缩(bitmap.CompressFormat.JPEG,90,流);
byte[]byte_arr=stream.toByteArray();
字符串image_str=Base64.encodeToString(byte_arr,Base64.NO_WRAP | Base64.URL_SAFE);
ArrayList nameValuePairs=新的ArrayList();
添加(新的BasicNameValuePair(“源”、“安卓”);
添加(新的BasicNameValuePair(“source_版本”,“1.0.1”);
nameValuePairs.添加(新的BasicNameValuePairs(“场馆名称”、“苏打酒吧”);
添加(新的BasicNameValuePair(“艺术家名称”、“Led Zepplin”);
添加(新的BasicNameValuePair(“照片”,图片_str));
试一试{
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost HttpPost=新的HttpPost(url);
UrlEncodedFormEntity实体=新的UrlEncodedFormEntity(nameValuePairs,“UTF-8”);
httppost.setEntity(实体);
/*ResponseHandler=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());
字符串\u字符串\u响应=convertResponseToString(响应);
System.out.println(“响应内容”+字符串响应);
}捕获(例外e){
System.out.println(“http连接中的错误”+e.toString());
}
}

404
未找到页面的响应代码
,因此请与服务器联系以获取更多信息,您必须检查服务器端。404是未找到页面的代码。请确保您尝试访问的链接可访问。您也可以在浏览器中检查。