0

I am definitely not a computer guru. :)

I get an http 403 error when trying to upload a file on my website through an applet. This means that it is forbidden. Maybe it is a regular behavior, for uploading through http protocol may be not allowed. Is it true? Then how to do it? I would like my applet to upload little files on a specific folder of the server.

here is the code :

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
    }

}

Thanks for helping...

Sylvain B.
  • 719
  • 5
  • 31

1 Answers1

0

Go through the link. Hope it will help you.

http://stackoverflow.com/questions/1599018/java-applet-to-upload-a-file?rq=1
  • If he is getting a 403, that means it hit the remote server, so I don't think that posting applies. It sounds to me like the remote server requires some credentials to post to. – CodeChimp Dec 10 '13 at 15:20
  • @Sylvain B. What was the server side solution? – Chepech Dec 05 '16 at 07:52