Android post file and text

后端 未结 1 987
半阙折子戏
半阙折子戏 2021-01-15 03:49

I have 2 methods at the moment 1 to post a file, and another to post some text, they are below

Post the data...

public void postData() {  
    // Cre         


        
相关标签:
1条回答
  • 2021-01-15 04:42

    You can use something like this:

    File file = new File("FileToSend.txt");
    HttpClient client = new HttpClient();
    
    String url = "http://www.yourdomain.com/destination.php";
    PostMethod postMethod = new PostMethod(url);
    
    Part[] parts = {new FilePart(file.getName(), file)};
    postMethod.setParameter("name", "value"); // set parameters like this instead in separate call
    
    postMethod.setRequestEntity( new MultipartRequestEntity(parts, postMethod.getParams()));
    
    int status = client.executeMethod(postMethod);
    
    0 讨论(0)
提交回复
热议问题