Android发送图片并保存网址

Kis*_*ore 8 android

可能重复:
在android中发送帖子数据

如何通过http post发送图像以及表单数据,如图像名称等

到指定的url ..这是aspx的url .

Ven*_*nky 19

检查此代码是否包含标题,标题,名称等发送图像,

    HttpClient httpClient = new DefaultHttpClient();
    HttpPost postRequest = new HttpPost("You Link");
    MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    reqEntity.addPart("name", new StringBody("Name"));
    reqEntity.addPart("Id", new StringBody("ID"));
    reqEntity.addPart("title",new StringBody("TITLE"));
    reqEntity.addPart("caption", new StringBody("Caption"));
    try{
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        bitmap.compress(CompressFormat.JPEG, 75, bos);
        byte[] data = bos.toByteArray();
        ByteArrayBody bab = new ByteArrayBody(data, "forest.jpg");
        reqEntity.addPart("picture", bab);
    }
    catch(Exception e){
        //Log.v("Exception in Image", ""+e);
        reqEntity.addPart("picture", new StringBody(""));
    }
    postRequest.setEntity(reqEntity);       
    HttpResponse response = httpClient.execute(postRequest);
    BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
    String sResponse;
    StringBuilder s = new StringBuilder();
    while ((sResponse = reader.readLine()) != null) {
        s = s.append(sResponse);
    }
Run Code Online (Sandbox Code Playgroud)

位图是图像位图.

如果您发现任何困难,请告诉我.

谢谢Venky.

  • 但这不会发生在 Android Studio @Venky (2认同)