Adblock breaks this site

Writing to Webserver[help]

Discussion in 'Programming General' started by dont leech, Jun 11, 2009.

  1. dont leech

    dont leech Active Member

    Joined:
    Aug 12, 2008
    Posts:
    186
    Referrals:
    0
    Sythe Gold:
    0
    Writing to Webserver[help]

    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?
     
  2. Nullware

    Nullware Guru

    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0
    Writing to Webserver[help]

    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.
     
  3. dont leech

    dont leech Active Member

    Joined:
    Aug 12, 2008
    Posts:
    186
    Referrals:
    0
    Sythe Gold:
    0
    Writing to Webserver[help]

    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?
     
  4. Nullware

    Nullware Guru

    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0
    Writing to Webserver[help]

    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..
     
  5. dont leech

    dont leech Active Member

    Joined:
    Aug 12, 2008
    Posts:
    186
    Referrals:
    0
    Sythe Gold:
    0
    Writing to Webserver[help]

    I will start reading some tuts.


    Thanks for your time, ill post if i need further assistance.
     
< [TUT][C#]The Try/Catch/Finally statment. | [C# Source] GELookup Class >


 
 
Adblock breaks this site