java.net.NoRouteToHostException:没有到主机的路由(主机不可达)

时间:2019-07-26 13:09:25

标签: java http httpclient

正在尝试用Java上传文件时,收到以下错误消息。

java.net.NoRouteToHostException:没有到主机的路由(主机不可达)

这是我的Java课

public class MultipartFileUploader {

    public static void main(String[] args) {
        String charset = "UTF-8";
        File uploadFile1 = new File("/home/jarin/Downloads/IMG_20190723_133557.jpg");
        File uploadFile2 = new File("e:/Test/PIC2.JPG");
        String requestURL = "http://192.168.0.104/AndroidFileUpload/fileUpload.php";

        try {
            MultipartUtility multipart = new MultipartUtility(requestURL, charset);

        /*  multipart.addHeaderField("User-Agent", "CodeJava");
            multipart.addHeaderField("Test-Header", "Header-Value");

            multipart.addFormField("description", "Cool Pictures");
            multipart.addFormField("keywords", "Java,upload,Spring");*/

            multipart.addFilePart("image", uploadFile1);
            multipart.addFormField("website","www.google.co.in");
            multipart.addFormField("email","test@gmail.com");
            //multipart.addFilePart("fileUpload", uploadFile2);

            List<String> response = multipart.finish();

            System.out.println("SERVER REPLIED:");

            for (String line : response) {
                System.out.println(line);
            }

        } catch (IOException ex) {
            System.err.println(ex);
        }
    }
}

0 个答案:

没有答案