Writing to Webserver[help]

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

Writing to Webserver[help]
  1. Unread #1 - Jun 11, 2009 at 1:39 PM
  2. dont leech
    Joined:
    Aug 12, 2008
    Posts:
    186
    Referrals:
    0
    Sythe Gold:
    0

    dont leech Active Member

    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?
     
  3. Unread #2 - Jun 11, 2009 at 7:06 PM
  4. Nullware
    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0

    Nullware Guru

    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.
     
  5. Unread #3 - Jun 11, 2009 at 7:28 PM
  6. dont leech
    Joined:
    Aug 12, 2008
    Posts:
    186
    Referrals:
    0
    Sythe Gold:
    0

    dont leech Active Member

    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?
     
  7. Unread #4 - Jun 11, 2009 at 9:49 PM
  8. Nullware
    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0

    Nullware Guru

    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..
     
  9. Unread #5 - Jun 11, 2009 at 11:01 PM
  10. dont leech
    Joined:
    Aug 12, 2008
    Posts:
    186
    Referrals:
    0
    Sythe Gold:
    0

    dont leech Active Member

    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 >

Users viewing this thread
1 guest


 
 
Adblock breaks this site