Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: cant get rid of http connection

  1. #1
    Junior Member
    Join Date
    Jul 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default cant get rid of http connection

    Hi All,

    I am working on posting multiple request to a server using HTTPClient . First i create a HTTPConnection

    (HTTPClient API: Class HTTPConnection) and then send a post request.

    For every post thats made the HTTPResponse is read and processed. After i process the Response, i try to stop the

    connection, but it doesn't seem to work. Although it stops when i don't play with the response. I am probably missing

    some cleanup here for reponse, but there doesn't seem to be a close method for

    HTTPResponse(HTTPClient API: Class HTTPResponse). This is how the

    code looks ...

     
    HTTPConnection httpCon = null;
    URL myURL = new URL(url);
    httpCon = new HTTPConnection(myURL);
    HTTPConnection.setDefaultAllowUserInteraction(false);
    httpCon.setAllowUserInteraction(false);
     
    ArrayList<NVPair> al = new ArrayList<NVPair>();
    NVPair nvp = new NVPair("Content-Type",
    "application/x-www-form-urlencoded;charset=UTF-8");
    al.add(nvp);
    NVPair[] nvHeaderArray = (NVPair[]) al.toArray(new NVPair[] {});
    httpCon.setDefaultHeaders(nvHeaderArray);
     
    HTTPResponse response = null;
    response = httpCon.Post(url, data, nvHeaderArray);
     
    InputStream is = response.getInputStream();
    is.close();
    httpCon.stop();

    I am not sure why the old connection doesn't die. Can anyone help me with this? Thanks everyone.

    Thanks,
    Kartik


  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,282
    My Mood
    Happy
    Thanks
    70
    Thanked 158 Times in 154 Posts

    Default Re: cant get rid of http connection

    I'm not so sure you would need to close the inputstream and stop the connection. What's the actual problem you are seeing?

    // Json