×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    Dec 2009
    Location
    chennai
    Posts
    137

    Question Request-URI Too Long: 414

    Hi,

    I got this exception Request-URI Too Long: 414 while posting the data through HttpConnection.

    I want to post xml data as string format with URL to Webservice.
    I did encode the that xml string and post with URL.
    If URL length is too long means i got htis exception.

    How to resolve this issue?
    Is anyother way to posting the data?
    Bharath... :)

  2. #2
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: Request-URI Too Long: 414

    Quote Originally Posted by bhakki View Post
    Hi,

    I got this exception Request-URI Too Long: 414 while posting the data through HttpConnection.

    I want to post xml data as string format with URL to Webservice.
    I did encode the that xml string and post with URL.
    If URL length is too long means i got htis exception.

    How to resolve this issue?
    Is anyother way to posting the data?
    If the URL length is too long you get this issue.

    Instead of sending this data xml as Query string, with http GET type of request, try to send it as POST request and write the entire data on output stream opened on the connection.

    for example see this:
    Code:
    void postViaHttpConnection(String url) throws IOException {
            HttpConnection c = null;
            InputStream is = null;
            OutputStream os = null;
            int rc;
    
            try {
                c = (HttpConnection)Connector.open(url);  // URL is only URL without any query string
    
                // Set the request method and headers
                c.setRequestMethod(HttpConnection.POST);
                c.setRequestProperty("If-Modified-Since",
                    "29 Oct 1999 19:43:31 GMT");
                c.setRequestProperty("User-Agent",
                    "Profile/MIDP-2.0 Configuration/CLDC-1.0");
                c.setRequestProperty("Content-Language", "en-US");
    
                // Getting the output stream may flush the headers
                os = c.openOutputStream();
                os.write("Put Your XML data here\n".getBytes());
                os.flush();           // Optional, getResponseCode will flush
    
                // Getting the response code will open the connection,
                // send the request, and read the HTTP response headers.
                // The headers are stored until requested.
                rc = c.getResponseCode();
                if (rc != HttpConnection.HTTP_OK) {
                    throw new IOException("HTTP response code: " + rc);
                }
    
                is = c.openInputStream();
    
                // Get the ContentType
                String type = c.getType();
                processType(type);
    
                // Get the length and process the data
                int len = (int)c.getLength();
                if (len > 0) {
                     int actual = 0;
                     int bytesread = 0 ;
                     byte[] data = new byte[len];
                     while ((bytesread != len) && (actual != -1)) {
                        actual = is.read(data, bytesread, len - bytesread);
                        bytesread += actual;
                     }
                    process(data);
                } else {
                    int ch;
                    while ((ch = is.read()) != -1) {
                        process((byte)ch);
                    }
                }
            } catch (ClassCastException e) {
                throw new IllegalArgumentException("Not an HTTP URL");
            } finally {
                if (is != null)
                    is.close();
                if (os != null)
                    os.close();
                if (c != null)
                    c.close();
            }
        }
    Thanks,
    Ekta

  3. #3
    Registered User
    Join Date
    Dec 2009
    Location
    chennai
    Posts
    137

    Re: Request-URI Too Long: 414

    Hi,

    I got the Internal Server Error: 500 exception.
    I used requested method as HttpConnection.POST.
    Bharath... :)

  4. #4
    Nokia Developer Champion
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Request-URI Too Long: 414

    well 500 internal server error means that your script on the server is crashing or doing wrong things....
    Anyways, such an error is an error on the server side not on your clien-tside, so fix that issue first
    Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them.

  5. #5
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: Request-URI Too Long: 414

    Quote Originally Posted by bhakki View Post
    Hi,

    I got the Internal Server Error: 500 exception.
    I used requested method as HttpConnection.POST.
    Refer to this URL for details about Internal Server Error: 500
    http://www.checkupdown.com/status/E500.html

    If your server is programed to read the request data from the client's request Query String, check that its not crashing due to the absence of Query String in your POST request.
    Check is the server capable for read request parameters i.e. post data from the request object.
    Thanks,
    Ekta

  6. #6
    Registered User
    Join Date
    Dec 2009
    Location
    chennai
    Posts
    137

    Re: Request-URI Too Long: 414

    Thanks... Its working fine. I made one mistake in RequestProperty.
    But in server side some special symbol added at end of requested parameter. Like infinite '\0' added to end of the requested parameter.
    In client side, there no special symbols in requested parameter.

    How to resolve this issue?
    Last edited by bhakki; 2010-06-24 at 14:12.
    Bharath... :)

  7. #7
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: Request-URI Too Long: 414

    cut paste the codelet here, which you are using to send request parameters on the stream to the server.
    Also cut paste what you get on server side frome request objects and how... codelet.
    Thanks,
    Ekta

  8. #8
    Registered User
    Join Date
    Dec 2009
    Location
    chennai
    Posts
    137

    Re: Request-URI Too Long: 414

    In client side,
    d0699d5e514b93af84bdd3da9ac56e4a
    This is the last parameter value to be sent through requested parameter

    In server side,
    d0699d5e514b93af84bdd3da9ac56e4a\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0......(its showing too long)
    This is im get it from server side.

    I followed as per as your example code in first reply...
    Bharath... :)

  9. #9
    Registered User
    Join Date
    Oct 2009
    Location
    Noida
    Posts
    941

    Re: Request-URI Too Long: 414

    Quote Originally Posted by bhakki View Post
    In client side,
    d0699d5e514b93af84bdd3da9ac56e4a
    This is the last parameter value to be sent through requested parameter

    In server side,
    d0699d5e514b93af84bdd3da9ac56e4a\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0......(its showing too long)
    This is im get it from server side.

    I followed as per as your example code in first reply...
    Try to trim() your string before writing it on the output stream like this:
    In headers set the Content-Length

    c.setRequestProperty("Content-Length", (xmlDataString.trim()).length());

    before -
    // Getting the output stream may flush the headers
    os = c.openOutputStream();



    os.write((xmlDataString.trim()).getBytes());

    comment out.flush();
    Thanks,
    Ekta

  10. #10
    Registered User
    Join Date
    Dec 2009
    Location
    chennai
    Posts
    137

    Re: Request-URI Too Long: 414

    Thanks Ekta.
    Its working as per as ur idea.
    Bharath... :)

Similar Threads

  1. SIP/2.0 400 Bad Request - Request-URI Domain Not Valid
    By fly31 in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2009-01-09, 14:00
  2. Problem with EventList.items(int i0, long l0, long l1, boolean b0)
    By suvro in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2007-10-12, 07:28
  3. Question about long connection Http request!
    By defaulty in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2004-01-03, 07:41

Posting Permissions

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