android http 附件

一:服务器端:

1:struts-config.xml

Xml代码   收藏代码
  1.   <?xml version="1.0" encoding="UTF-8" ?>   
  2.   <!DOCTYPE struts-config (View Source for full doctype...)>   
  3. <struts-config>  
  4. <form-beans>  
  5.   <form-bean name="videoForm" type="cn.itcast.formbean.VideoForm" />   
  6.   </form-beans>  
  7. <action-mappings>  
  8. <action path="/video/list" name="videoForm" scope="request" type="cn.itcast.action.VideoListAction">  
  9.   <forward name="video" path="/WEB-INF/page/videos.jsp" />   
  10.   <forward name="jsonvideo" path="/WEB-INF/page/jsonvideos.jsp" />   
  11.   </action>  
  12. <action path="/video/manage" name="videoForm" scope="request" type="cn.itcast.action.VideoManageAction" parameter="method">  
  13.   <forward name="result" path="/WEB-INF/page/result.jsp" />   
  14.   </action>  
  15.   </action-mappings>  
  16.   </struts-config>  

 

2:VideoForm

Java代码   收藏代码
  1. package cn.itcast.formbean;  
  2.   
  3. import org.apache.struts.action.ActionForm;  
  4. import org.apache.struts.upload.FormFile;  
  5.   
  6. public class VideoForm extends ActionForm {  
  7.     private String format;  
  8.     private String title;     
  9.     private Integer timelength;  
  10.     private FormFile video;  
  11.       
  12.     public FormFile getVideo() {  
  13.         return video;  
  14.     }  
  15.   
  16.     public void setVideo(FormFile video) {  
  17.         this.video = video;  
  18.     }  
  19.   
  20.     public String getTitle() {  
  21.         return title;  
  22.     }  
  23.   
  24.     public void setTitle(String title) {  
  25.         this.title = title;  
  26.     }  
  27.   
  28.     public Integer getTimelength() {  
  29.         return timelength;  
  30.     }  
  31.   
  32.     public void setTimelength(Integer timelength) {  
  33.         this.timelength = timelength;  
  34.     }  
  35.   
  36.     public String getFormat() {  
  37.         return format;  
  38.     }  
  39.   
  40.     public void setFormat(String format) {  
  41.         this.format = format;  
  42.     }  
  43.       
  44. }  

 

3:VideoManageAction.java

Java代码   收藏代码
  1. package cn.itcast.action;  
  2.   
  3. import java.io.File;  
  4. import java.io.FileOutputStream;  
  5. import java.io.InputStream;  
  6.   
  7. import javax.servlet.http.HttpServletRequest;  
  8. import javax.servlet.http.HttpServletResponse;  
  9.   
  10. import org.apache.struts.action.ActionForm;  
  11. import org.apache.struts.action.ActionForward;  
  12. import org.apache.struts.action.ActionMapping;  
  13. import org.apache.struts.actions.DispatchAction;  
  14.   
  15. import cn.itcast.formbean.VideoForm;  
  16. import cn.itcast.utils.StreamTool;  
  17.   
  18. public class VideoManageAction extends DispatchAction {  
  19.       
  20.     public ActionForward save(ActionMapping mapping, ActionForm form,  
  21.             HttpServletRequest request, HttpServletResponse response)  
  22.             throws Exception {  
  23.         VideoForm formbean = (VideoForm)form;  
  24.         if("GET".equals(request.getMethod())){  
  25.             byte[] data = request.getParameter("title").getBytes("ISO-8859-1");  
  26.             String title = new String(data, "UTF-8");  
  27.             System.out.println("title:"+ title);  
  28.             System.out.println("timelength:"+ formbean.getTimelength());  
  29.         }else{  
  30.             System.out.println("title:"+ formbean.getTitle());  
  31.             System.out.println("timelength:"+ formbean.getTimelength());  
  32.         }  
  33.         //下面完成视频文件的保存  
  34.         if(formbean.getVideo()!=null && formbean.getVideo().getFileSize()>0){  
  35.             String realpath = request.getSession().getServletContext().getRealPath("/video");  
  36.             System.out.println(realpath);  
  37.             File dir = new File(realpath);  
  38.             if(!dir.exists()) dir.mkdirs();  
  39.             File videoFile = new File(dir, formbean.getVideo().getFileName());  
  40.             FileOutputStream outStream = new FileOutputStream(videoFile);  
  41.             outStream.write(formbean.getVideo().getFileData());  
  42.             outStream.close();  
  43.         }  
  44.         return mapping.findForward("result");  
  45.     }  
  46.       
  47.     public ActionForward getXML(ActionMapping mapping, ActionForm form,  
  48.             HttpServletRequest request, HttpServletResponse response)  
  49.             throws Exception {  
  50.         InputStream inStream = request.getInputStream();  
  51.         byte[] data = StreamTool.readInputStream(inStream);  
  52.         String xml = new String(data, "UTF-8");  
  53.         System.out.println(xml);  
  54.         return mapping.findForward("result");  
  55.     }  
  56. }  

 

4:result.jsp

Java代码   收藏代码
  1. <%@ page language="java" contentType="text/html; charset=UTF-8"  
  2.     pageEncoding="UTF-8"%>  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  4. <html>  
  5. <head>  
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  7. <title>Insert title here</title>  
  8. </head>  
  9. <body>  
  10.     保存完成  
  11. </body>  
  12. </html>  

 

二:客户端

1:FormFile.java

Java代码   收藏代码
  1. package cn.itcast.utils;  
  2.   
  3. import java.io.File;  
  4. import java.io.FileInputStream;  
  5. import java.io.FileNotFoundException;  
  6. import java.io.InputStream;  
  7.   
  8. /** 
  9.  * 上传文件 
  10.  */  
  11. public class FormFile {  
  12.     /* 上传文件的数据 */  
  13.     private byte[] data;  
  14.     private InputStream inStream;  
  15.     private File file;  
  16.     /* 文件名称 */  
  17.     private String filname;  
  18.     /* 请求参数名称*/  
  19.     private String parameterName;  
  20.     /* 内容类型 */  
  21.     private String contentType = "application/octet-stream";  
  22.       
  23.     public FormFile(String filname, byte[] data, String parameterName, String contentType) {  
  24.         this.data = data;  
  25.         this.filname = filname;  
  26.         this.parameterName = parameterName;  
  27.         if(contentType!=nullthis.contentType = contentType;  
  28.     }  
  29.       
  30.     public FormFile(String filname, File file, String parameterName, String contentType) {  
  31.         this.filname = filname;  
  32.         this.parameterName = parameterName;  
  33.         this.file = file;  
  34.         try {  
  35.             this.inStream = new FileInputStream(file);  
  36.         } catch (FileNotFoundException e) {  
  37.             e.printStackTrace();  
  38.         }  
  39.         if(contentType!=nullthis.contentType = contentType;  
  40.     }  
  41.       
  42.     public File getFile() {  
  43.         return file;  
  44.     }  
  45.   
  46.     public InputStream getInStream() {  
  47.         return inStream;  
  48.     }  
  49.   
  50.     public byte[] getData() {  
  51.         return data;  
  52.     }  
  53.   
  54.     public String getFilname() {  
  55.         return filname;  
  56.     }  
  57.   
  58.     public void setFilname(String filname) {  
  59.         this.filname = filname;  
  60.     }  
  61.   
  62.     public String getParameterName() {  
  63.         return parameterName;  
  64.     }  
  65.   
  66.     public void setParameterName(String parameterName) {  
  67.         this.parameterName = parameterName;  
  68.     }  
  69.   
  70.     public String getContentType() {  
  71.         return contentType;  
  72.     }  
  73.   
  74.     public void setContentType(String contentType) {  
  75.         this.contentType = contentType;  
  76.     }  
  77.       
  78. }  

 

2:StreamTool

Java代码   收藏代码
  1. package cn.itcast.utils;  
  2.   
  3. import java.io.ByteArrayOutputStream;  
  4. import java.io.InputStream;  
  5.   
  6. public class StreamTool {  
  7.   
  8.     /** 
  9.      * 从输入流读取数据 
  10.      * @param inStream 
  11.      * @return 
  12.      * @throws Exception 
  13.      */  
  14.     public static byte[] readInputStream(InputStream inStream) throws Exception{  
  15.         ByteArrayOutputStream outSteam = new ByteArrayOutputStream();  
  16.         byte[] buffer = new byte[1024];  
  17.         int len = 0;  
  18.         while( (len = inStream.read(buffer)) !=-1 ){  
  19.             outSteam.write(buffer, 0, len);  
  20.         }  
  21.         outSteam.close();  
  22.         inStream.close();  
  23.         return outSteam.toByteArray();  
  24.     }  
  25. }  

 

3:SocketHttpRequester.java

Java代码   收藏代码
  1. package cn.itcast.utils;  
  2.   
  3. import java.io.BufferedReader;  
  4. import java.io.ByteArrayOutputStream;  
  5. import java.io.DataOutputStream;  
  6. import java.io.InputStream;  
  7. import java.io.InputStreamReader;  
  8. import java.io.OutputStream;  
  9. import java.net.HttpURLConnection;  
  10. import java.net.InetAddress;  
  11. import java.net.Socket;  
  12. import java.net.URL;  
  13. import java.net.URLEncoder;  
  14. import java.util.ArrayList;  
  15. import java.util.List;  
  16. import java.util.Map;  
  17.   
  18. import org.apache.http.HttpResponse;  
  19. import org.apache.http.NameValuePair;  
  20. import org.apache.http.client.HttpClient;  
  21. import org.apache.http.client.entity.UrlEncodedFormEntity;  
  22. import org.apache.http.client.methods.HttpPost;  
  23. import org.apache.http.impl.client.DefaultHttpClient;  
  24. import org.apache.http.message.BasicNameValuePair;  
  25.   
  26. public class SocketHttpRequester {  
  27.     /** 
  28.      * 发送xml数据 
  29.      * @param path 请求地址 
  30.      * @param xml xml数据 
  31.      * @param encoding 编码 
  32.      * @return 
  33.      * @throws Exception 
  34.      */  
  35.     public static byte[] postXml(String path, String xml, String encoding) throws Exception{  
  36.         byte[] data = xml.getBytes(encoding);  
  37.         URL url = new URL(path);  
  38.         HttpURLConnection conn = (HttpURLConnection)url.openConnection();  
  39.         conn.setRequestMethod("POST");  
  40.         conn.setDoOutput(true);  
  41.         conn.setRequestProperty("Content-Type""text/xml; charset="+ encoding);  
  42.         conn.setRequestProperty("Content-Length", String.valueOf(data.length));  
  43.         conn.setConnectTimeout(5 * 1000);  
  44.         OutputStream outStream = conn.getOutputStream();  
  45.         outStream.write(data);  
  46.         outStream.flush();  
  47.         outStream.close();  
  48.         if(conn.getResponseCode()==200){  
  49.             return readStream(conn.getInputStream());  
  50.         }  
  51.         return null;  
  52.     }  
  53.       
  54.     /** 
  55.      * 直接通过HTTP协议提交数据到服务器,实现如下面表单提交功能: 
  56.      *   <FORM METHOD=POST ACTION="http://192.168.0.200:8080/ssi/fileload/test.do" enctype="multipart/form-data"> 
  57.             <INPUT TYPE="text" NAME="name"> 
  58.             <INPUT TYPE="text" NAME="id"> 
  59.             <input type="file" name="imagefile"/> 
  60.             <input type="file" name="zip"/> 
  61.          </FORM> 
  62.      * @param path 上传路径(注:避免使用localhost或127.0.0.1这样的路径测试,因为它会指向手机模拟器,你可以使用http://www.itcast.cn或http://192.168.1.10:8080这样的路径测试) 
  63.      * @param params 请求参数 key为参数名,value为参数值 
  64.      * @param file 上传文件 
  65.      */  
  66.     public static boolean post(String path, Map<String, String> params, FormFile[] files) throws Exception{       
  67.         final String BOUNDARY = "---------------------------7da2137580612"//数据分隔线  
  68.         final String endline = "--" + BOUNDARY + "--\r\n";//数据结束标志  
  69.           
  70.         int fileDataLength = 0;  
  71.         for(FormFile uploadFile : files){//得到文件类型数据的总长度  
  72.             StringBuilder fileExplain = new StringBuilder();  
  73.             fileExplain.append("--");  
  74.             fileExplain.append(BOUNDARY);  
  75.             fileExplain.append("\r\n");  
  76.             fileExplain.append("Content-Disposition: form-data;name=\""+ uploadFile.getParameterName()+"\";filename=\""+ uploadFile.getFilname() + "\"\r\n");  
  77.             fileExplain.append("Content-Type: "+ uploadFile.getContentType()+"\r\n\r\n");  
  78.             fileExplain.append("\r\n");  
  79.             fileDataLength += fileExplain.length();  
  80.             if(uploadFile.getInStream()!=null){  
  81.                 fileDataLength += uploadFile.getFile().length();  
  82.             }else{  
  83.                 fileDataLength += uploadFile.getData().length;  
  84.             }  
  85.         }  
  86.         StringBuilder textEntity = new StringBuilder();  
  87.         for (Map.Entry<String, String> entry : params.entrySet()) {//构造文本类型参数的实体数据  
  88.             textEntity.append("--");  
  89.             textEntity.append(BOUNDARY);  
  90.             textEntity.append("\r\n");  
  91.             textEntity.append("Content-Disposition: form-data; name=\""+ entry.getKey() + "\"\r\n\r\n");  
  92.             textEntity.append(entry.getValue());  
  93.             textEntity.append("\r\n");  
  94.         }  
  95.         //计算传输给服务器的实体数据总长度  
  96.         int dataLength = textEntity.toString().getBytes().length + fileDataLength +  endline.getBytes().length;  
  97.           
  98.         URL url = new URL(path);  
  99.         int port = url.getPort()==-1 ? 80 : url.getPort();  
  100.         Socket socket = new Socket(InetAddress.getByName(url.getHost()), port);          
  101.         OutputStream outStream = socket.getOutputStream();  
  102.         //下面完成HTTP请求头的发送  
  103.         String requestmethod = "POST "+ url.getPath()+" HTTP/1.1\r\n";  
  104.         outStream.write(requestmethod.getBytes());  
  105.         String accept = "Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*\r\n";  
  106.         outStream.write(accept.getBytes());  
  107.         String language = "Accept-Language: zh-CN\r\n";  
  108.         outStream.write(language.getBytes());  
  109.         String contenttype = "Content-Type: multipart/form-data; boundary="+ BOUNDARY+ "\r\n";  
  110.         outStream.write(contenttype.getBytes());  
  111.         String contentlength = "Content-Length: "+ dataLength + "\r\n";  
  112.         outStream.write(contentlength.getBytes());  
  113.         String alive = "Connection: Keep-Alive\r\n";  
  114.         outStream.write(alive.getBytes());  
  115.         String host = "Host: "+ url.getHost() +":"+ port +"\r\n";  
  116.         outStream.write(host.getBytes());  
  117.         //写完HTTP请求头后根据HTTP协议再写一个回车换行  
  118.         outStream.write("\r\n".getBytes());  
  119.         //把所有文本类型的实体数据发送出来  
  120.         outStream.write(textEntity.toString().getBytes());           
  121.         //把所有文件类型的实体数据发送出来  
  122.         for(FormFile uploadFile : files){  
  123.             StringBuilder fileEntity = new StringBuilder();  
  124.             fileEntity.append("--");  
  125.             fileEntity.append(BOUNDARY);  
  126.             fileEntity.append("\r\n");  
  127.             fileEntity.append("Content-Disposition: form-data;name=\""+ uploadFile.getParameterName()+"\";filename=\""+ uploadFile.getFilname() + "\"\r\n");  
  128.             fileEntity.append("Content-Type: "+ uploadFile.getContentType()+"\r\n\r\n");  
  129.             outStream.write(fileEntity.toString().getBytes());  
  130.             if(uploadFile.getInStream()!=null){  
  131.                 byte[] buffer = new byte[1024];  
  132.                 int len = 0;  
  133.                 while((len = uploadFile.getInStream().read(buffer, 01024))!=-1){  
  134.                     outStream.write(buffer, 0, len);  
  135.                 }  
  136.                 uploadFile.getInStream().close();  
  137.             }else{  
  138.                 outStream.write(uploadFile.getData(), 0, uploadFile.getData().length);  
  139.             }  
  140.             outStream.write("\r\n".getBytes());  
  141.         }  
  142.         //下面发送数据结束标志,表示数据已经结束  
  143.         outStream.write(endline.getBytes());  
  144.           
  145.         BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));  
  146.         if(reader.readLine().indexOf("200")==-1){//读取web服务器返回的数据,判断请求码是否为200,如果不是200,代表请求失败  
  147.             return false;  
  148.         }  
  149.         outStream.flush();  
  150.         outStream.close();  
  151.         reader.close();  
  152.         socket.close();  
  153.         return true;  
  154.     }  
  155.       
  156.     /**  
  157.      * 提交数据到服务器  
  158.      * @param path 上传路径(注:避免使用localhost或127.0.0.1这样的路径测试,因为它会指向手机模拟器,你可以使用http://www.itcast.cn或http://192.168.1.10:8080这样的路径测试)  
  159.      * @param params 请求参数 key为参数名,value为参数值  
  160.      * @param file 上传文件  
  161.      */  
  162.     public static boolean post(String path, Map<String, String> params, FormFile file) throws Exception{  
  163.        return post(path, params, new FormFile[]{file});  
  164.     }  
  165.     /** 
  166.      * 提交数据到服务器 
  167.      * @param path 上传路径(注:避免使用localhost或127.0.0.1这样的路径测试,因为它会指向手机模拟器,你可以使用http://www.itcast.cn或http://192.168.1.10:8080这样的路径测试) 
  168.      * @param params 请求参数 key为参数名,value为参数值 
  169.      * @param encode 编码 
  170.      */  
  171.     public static byte[] postFromHttpClient(String path, Map<String, String> params, String encode) throws Exception{  
  172.         List<NameValuePair> formparams = new ArrayList<NameValuePair>();//用于存放请求参数  
  173.         for(Map.Entry<String, String> entry : params.entrySet()){  
  174.             formparams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));  
  175.         }  
  176.         UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, encode);  
  177.         HttpPost httppost = new HttpPost(path);  
  178.         httppost.setEntity(entity);  
  179.         HttpClient httpclient = new DefaultHttpClient();//看作是浏览器  
  180.         HttpResponse response = httpclient.execute(httppost);//发送post请求       
  181.         return readStream(response.getEntity().getContent());  
  182.     }  
  183.   
  184.     /** 
  185.      * 发送请求 
  186.      * @param path 请求路径 
  187.      * @param params 请求参数 key为参数名称 value为参数值 
  188.      * @param encode 请求参数的编码 
  189.      */  
  190.     public static byte[] post(String path, Map<String, String> params, String encode) throws Exception{  
  191.         //String params = "method=save&name="+ URLEncoder.encode("老毕", "UTF-8")+ "&age=28&";//需要发送的参数  
  192.         StringBuilder parambuilder = new StringBuilder("");  
  193.         if(params!=null && !params.isEmpty()){  
  194.             for(Map.Entry<String, String> entry : params.entrySet()){  
  195.                 parambuilder.append(entry.getKey()).append("=")  
  196.                     .append(URLEncoder.encode(entry.getValue(), encode)).append("&");  
  197.             }  
  198.             parambuilder.deleteCharAt(parambuilder.length()-1);  
  199.         }  
  200.         byte[] data = parambuilder.toString().getBytes();  
  201.         URL url = new URL(path);  
  202.         HttpURLConnection conn = (HttpURLConnection)url.openConnection();  
  203.         conn.setDoOutput(true);//允许对外发送请求参数  
  204.         conn.setUseCaches(false);//不进行缓存  
  205.         conn.setConnectTimeout(5 * 1000);  
  206.         conn.setRequestMethod("POST");  
  207.         //下面设置http请求头  
  208.         conn.setRequestProperty("Accept""image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");  
  209.         conn.setRequestProperty("Accept-Language""zh-CN");  
  210.         conn.setRequestProperty("User-Agent""Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)");  
  211.         conn.setRequestProperty("Content-Type""application/x-www-form-urlencoded");  
  212.         conn.setRequestProperty("Content-Length", String.valueOf(data.length));  
  213.         conn.setRequestProperty("Connection""Keep-Alive");  
  214.           
  215.         //发送参数  
  216.         DataOutputStream outStream = new DataOutputStream(conn.getOutputStream());  
  217.         outStream.write(data);//把参数发送出去  
  218.         outStream.flush();  
  219.         outStream.close();  
  220.         if(conn.getResponseCode()==200){  
  221.             return readStream(conn.getInputStream());  
  222.         }  
  223.         return null;  
  224.     }  
  225.       
  226.     /**  
  227.      * 读取流  
  228.      * @param inStream  
  229.      * @return 字节数组  
  230.      * @throws Exception  
  231.      */  
  232.     public static byte[] readStream(InputStream inStream) throws Exception{  
  233.         ByteArrayOutputStream outSteam = new ByteArrayOutputStream();  
  234.         byte[] buffer = new byte[1024];  
  235.         int len = -1;  
  236.         while( (len=inStream.read(buffer)) != -1){  
  237.             outSteam.write(buffer, 0, len);  
  238.         }  
  239.         outSteam.close();  
  240.         inStream.close();  
  241.         return outSteam.toByteArray();  
  242.     }  
  243. }  

 

4:MainActivity

Java代码   收藏代码
  1. package cn.itcast.uploaddata;  
  2.   
  3. import java.io.File;  
  4. import java.util.HashMap;  
  5. import java.util.Map;  
  6.   
  7. import cn.itcast.net.HttpRequest;  
  8. import cn.itcast.utils.FormFile;  
  9. import cn.itcast.utils.SocketHttpRequester;  
  10. import android.app.Activity;  
  11. import android.os.Bundle;  
  12. import android.os.Environment;  
  13. import android.util.Log;  
  14. import android.view.View;  
  15. import android.widget.Button;  
  16. import android.widget.EditText;  
  17. import android.widget.Toast;  
  18.   
  19. public class MainActivity extends Activity {  
  20.     private static final String TAG = "MainActivity";  
  21.     private EditText timelengthText;  
  22.     private EditText titleText;  
  23.     private EditText videoText;  
  24.       
  25.     @Override  
  26.     public void onCreate(Bundle savedInstanceState) {  
  27.         super.onCreate(savedInstanceState);  
  28.         setContentView(R.layout.main);  
  29.           
  30.        Button button = (Button) this.findViewById(R.id.button);  
  31.        timelengthText = (EditText) this.findViewById(R.id.timelength);  
  32.        videoText = (EditText) this.findViewById(R.id.video);  
  33.        titleText = (EditText) this.findViewById(R.id.title);  
  34.        button.setOnClickListener(new View.OnClickListener() {             
  35.             @Override  
  36.             public void onClick(View v) {  
  37.                 String title = titleText.getText().toString();  
  38.                 String timelength = timelengthText.getText().toString();  
  39.                 Map<String, String> params = new HashMap<String, String>();  
  40.                 params.put("method""save");  
  41.                 params.put("title", title);  
  42.                 params.put("timelength", timelength);  
  43.                 try {  
  44.                 //  HttpRequest.sendGetRequest("http://192.168.1.100:8080/videoweb/video/manage.do", params, "UTF-8");  
  45.                     File uploadFile = new File(Environment.getExternalStorageDirectory(), videoText.getText().toString());  
  46.                     FormFile formfile = new FormFile("02.mp3", uploadFile, "video""audio/mpeg");  
  47.                     SocketHttpRequester.post("http://192.168.1.100:8080/videoweb/video/manage.do", params, formfile);  
  48.                     Toast.makeText(MainActivity.this, R.string.success, 1).show();  
  49.                 } catch (Exception e) {  
  50.                     Toast.makeText(MainActivity.this, R.string.error, 1).show();  
  51.                     Log.e(TAG, e.toString());  
  52.                 }  
  53.             }  
  54.         });  
  55.           
  56.     }  
  57. }  

 

5:AndroidManifest.xml

Xml代码   收藏代码
  1.   <?xml version="1.0" encoding="utf-8" ?>   
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.itcast.uploaddata" android:versionCode="1" android:versionName="1.0">  
  3. <application android:icon="@drawable/icon" android:label="@string/app_name">  
  4.   <uses-library android:name="android.test.runner" />   
  5. <activity android:name=".MainActivity" android:label="@string/app_name">  
  6. <intent-filter>  
  7.   <action android:name="android.intent.action.MAIN" />   
  8.   <category android:name="android.intent.category.LAUNCHER" />   
  9.   </intent-filter>  
  10.   </activity>  
  11.   </application>  
  12.   <uses-sdk android:minSdkVersion="8" />   
  13. <!--  在SDCard中创建与删除文件权限  
  14.   -->   
  15.   <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />   
  16. <!--  往SDCard写入数据权限  
  17.   -->   
  18.   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />   
  19. <!--  访问网络的权限  
  20.   -->   
  21.   <uses-permission android:name="android.permission.INTERNET" />   
  22.   <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="cn.itcast.uploaddata" android:label="Tests for My App" />   
  23.   </manifest>  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值