Results 1 to 2 of 2
  1. #1
    psdev is offline Member
    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0

    Default Please Help: Java Applet 411 Length Required

    I am new to Java. I wrote an applet that sends results (int w and int p) to a server, and I get the "411 Length Required" error. What am I doing wrong? How do I set a Content-Length?

    This is the method that communicates with the server:

    Java Code:
    public void sendPoints1(int w, int p){
    
            try {
                String url = "http://somename.com:309/api/Results";
                String charset = "UTF-8";
                String query = String.format("?key=%s&value=%s",
                    URLEncoder.encode(String.valueOf(w), charset),
                    URLEncoder.encode(String.valueOf(p), charset));
                String length = String.valueOf((url + query).getBytes("UTF-8").length);
                
                HttpURLConnection connection = (HttpURLConnection) new URL(url + query).openConnection();
                connection.setRequestMethod("POST");
                connection.setRequestProperty("Content-Length", length);
                connection.connect();
                System.out.println("Responce Code:    " + connection.getResponseCode());
                System.out.println("Responce Message: " + connection.getResponseMessage());
            } catch (Exception e) {
                System.err.println(e.getMessage());
            }
           
        }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Please Help: Java Applet 411 Length Required

    How is this different from your previous same question? Locking this as duplicate. Please re-read the forum rules regarding duplicate posts.

Similar Threads

  1. Applet Expand Collpse Help Required
    By sarfrazasghar in forum Java Applets
    Replies: 0
    Last Post: 11-07-2012, 09:44 AM
  2. Difference between length() and length
    By mitra in forum New To Java
    Replies: 7
    Last Post: 07-28-2011, 01:46 AM
  3. java Array.length property
    By X-ion in forum New To Java
    Replies: 0
    Last Post: 04-07-2010, 09:45 AM
  4. Help required: regarding java.net.URL api
    By tarzan007 in forum New To Java
    Replies: 3
    Last Post: 11-07-2007, 05:46 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •