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...