Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
上载时发生java http 403错误_Java_Applet_Http Status Code 403 - Fatal编程技术网

上载时发生java http 403错误

上载时发生java http 403错误,java,applet,http-status-code-403,Java,Applet,Http Status Code 403,我绝对不是电脑大师。:) 当我试图通过小程序在我的网站上上传文件时,我收到一个http 403错误。 这意味着它是被禁止的。这可能是一种常规行为,因为通过http协议上传可能是不允许的。这是真的吗?那怎么办呢?我想让我的小程序在服务器的特定文件夹上上传小文件 代码如下: private static String folder = "http://..." //URL of the folder to upload to public void saveScore(Item h

我绝对不是电脑大师。:)

当我试图通过小程序在我的网站上上传文件时,我收到一个http 403错误。 这意味着它是被禁止的。这可能是一种常规行为,因为通过http协议上传可能是不允许的。这是真的吗?那怎么办呢?我想让我的小程序在服务器的特定文件夹上上传小文件

代码如下:

private static String folder = "http://..." //URL of the folder to upload to        

public void saveScore(Item hs) { //Item is a serializable object to save

    String filename = "s"+Integer.toString(hs.getScore())+".sco" ; // name of the file

    System.out.println("*** Trying to save file to : " + filename) ;

    try {
        //setting connection
        HttpURLConnection con =  (HttpURLConnection) new URL(folder+"/"+filename).openConnection() ;
        con.setDoInput(true); 
        con.setDoOutput(true);
        con.setRequestProperty ("Content-Type", "multipart/form-data");
        con.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");
        con.setChunkedStreamingMode(1024);
        con.setRequestMethod("PUT") ;       
        ObjectOutputStream oos = new ObjectOutputStream(con.getOutputStream()) ;

        //uploading
        oos.writeObject(hs) ;

        oos.flush() ;
        oos.close();

        //getting answer
        DataInputStream is = new DataInputStream(con.getInputStream()); 
        String s = is.readLine(); 
        is.close(); 

        System.out.println("** Answer **");
        System.out.println(s) ;

    } catch (IOException e) {
        e.printStackTrace(System.out) ; // gives me a 403 error
    }

}

感谢您帮助……

浏览此链接。希望它能帮助你

http://stackoverflow.com/questions/1599018/java-applet-to-upload-a-file?rq=1

如果他得到的是403,那就意味着它击中了远程服务器,所以我不认为这个帖子适用。在我看来,远程服务器需要一些凭证才能发送到。@Sylvain B.服务器端解决方案是什么?