URL connection -_-

Discussion in 'Plugin Development' started by coobro123, Dec 16, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    coobro123

    Hey guys
    Not in the best mood, I have tried about 40 times to connect via url. Not once successful.

    Ok, I basically want to check a url whether it outputs true or false thats really all it does
    So that the player joins and if the message on the url is true let them join if not don't.
    I am not going to post any code because you will just laugh at me :p
    Anyway, I know this is a bit pushy but can I get a whole code on this thing like including the if true statement, I am terrible with this work .-.

    Thanks again!
     
  2. coobro123
    The only thing that came in my mind was "what?". Smart people here don't laugh at people who try to code, we're here to help. Showing us what you've already tried gives us a better idea of what you're trying to do, and possibly helps us find your problem.

    So the message here is; may I see what you have already tried?
     
    Chinwe and Garris0n like this.
  3. Offline

    coobro123

    Lol, anyways its completely off. Here is all I have
    Code:
    try{
    URL u = new URL("http://minecraft.net/haspaid.jsp?user="+p.getName());
    } catch (Exception e) {
      e.printStackStrace();
    }
    
    That code hasn't been copied and pasted. But thats about all I know what to do, and I don't know in fact if that is right. xD
     
  4. Offline

    The_Doctor_123

  5. Offline

    TomShar

    Try this (not tested)
    Code:java
    1.  
    2. InputStream rd = null;
    3. try{
    4. URL obj = new URL("[url]http://minecraft.net/haspaid.jsp?user=[/url]"+p.getName());
    5. HttpURLConnection conn = (HttpURLConnection) obj.openConnection();
    6.  
    7. StringWriter writer = new StringWriter();
    8. IOUtils.copy(rd = conn.getInputStream(), writer);
    9. boolean exists = Boolean.parseBoolean(writer.toString());
    10.  
    11. if(exists) {
    12. // player exists
    13. } else {
    14. // player doesn'tt (not paid)
    15. }
    16.  
    17. } catch (IOException e) {
    18. throw e;
    19. }
    20. // EDIT: you'll want to close the streams
    21.  
    22. finally {
    23. try
    24. {
    25. if (rd != null) rd.close();
    26. }
    27. catch (Exception e) {/*dnt need to do anything here*/}
    28. }
    29.  
    30.  
     
  6. Offline

    rbrick

    This thread has actually helped me with another project i am working on. hehehe it does pay off to lurk around the plugin dev section :p
     
  7. Offline

    The_Doctor_123

    TomShar
    It could be as simple as..
    Code:java
    1. boolean in = Boolean.parseBoolean(new Scanner(new URL("website").openStream()).nextLine())

    In a try/catch, of course.
     
  8. Offline

    TomShar

    The_Doctor_123
    Maybe.. but what I have done, with a few additions, will let you do GET and POST with responses if required. It does what he needs and will probably help others who needs to do things similar more than a very precise answer.
     
  9. Offline

    The_Doctor_123

    TomShar
    What my code does is exactly what he wants. Keep code as precise as possible.
     
  10. Offline

    Garris0n

    Why would you read the premium value on login? All accounts that can log in have to be premium anyway.
     
Thread Status:
Not open for further replies.

Share This Page