• Log in or sign up for an account here: https://www.sythe.org/login

Writing to Webserver[help]

dont leech

Active Member
Joined
Aug 12, 2008
Sythe Gold
0
Messages
186
I want to write text in a txt doc that is located in a webserver.


Here is my code:
Code:
   public static void hey(){
   	   URL url = null;    
   URLConnection urlConn = null; 
   DataOutputStream dos = null;
   DataInputStream dis = null;
    try { 

    url = new URL("URL/.TXT");
    urlConn = url.openConnection(); 
    urlConn.setDoInput(true); 
    urlConn.setDoOutput(true); 
    urlConn.setUseCaches(false); 
    urlConn.setRequestProperty ("Content-Type", "application/x-www-form-urlencoded");

    dos = new DataOutputStream (urlConn.getOutputStream()); 
    String message = "NEW_ITEM=" + username + password;
    dos.writeBytes(message); 
    dos.flush(); 
    dos.close();
    dis = new DataInputStream(urlConn.getInputStream());
     String s = dis.readLine();   
    dis.close(); 

  }
   catch (MalformedURLException mue) { 
   	System.out.print("malformed url"); 
   }
   catch (IOException ioe) { 
  	System.out.print("IOEXCEPTION");  
  } 
   }

it throws IOExeption, what im i doing wrong?
 
The file doesn't exist and/or you don't have appropriate permissions.

Assuming you have direct access to that directory on the web server you would be better off just making a php page which accepts input in the form http://url/file.php?username=someone&password=somepass which you visit with your Java program. The PHP takes care of the file I/O which means it will have the permissions since it's directly on the web server.
 
I understand what you mean, but I don't have any php or enough java knowledge to do that, would it be easier to try to send the text via e mail?
 
The Java knowledge required for what I suggested is less than what you showed in the code you posted... as for the PHP knowledge very little is required and enough to do that can be picked up in an hour or so of reading a decent PHP tutorial/introduction.

Why do you even want to do this anyway?

And no by email is not very useful..
 
I will start reading some tuts.


Thanks for your time, ill post if i need further assistance.
 
duelarena.gg
Back
Top