×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    37

    How to create Http Connection by specifying the client port?

    When we create a Http connection using the class "HttpURLConnection", it seems that the client port is selected by system randomly. How can I specify a client port for a Http connection? For example, a client app(192.168.1.100:8000) wants to connect to a URL.

    Let me make my problem simple, I create a simple java HttpConnection app to test Http Digest Authentication which needs two registers. First register reqeust sends out from app, and then receives a 401. Then 2nd register with authentication header sends out. But the problem is these two register need the same port on the client side while the system uses different ports each time(two instances of HttpURLConnection). And I don't know how to use one instance of HttpURLConnection to send 2 requests.

    I try to use socket class but it still cannot let me specify the port on the client side.

    Also, how to specify client port for Http connection in J2ME?

    -----------------------------------------
    Thanks a lot! & Merry Christmas!

    Kevin,
    Last edited by SYTDeath; 2007-12-19 at 16:18.

  2. #2
    Registered User
    Join Date
    Oct 2007
    Posts
    24

    Re: How to create Http Connection by specifying the client port?

    HI

    String url = "http://192.168.1.100:8000";
    http = (HttpConnection) Connector.open(url);
    prtMsg(":: Establish the connection ::");
    // 1) Send request method Either Get or POST , depends upon your
    //application you can use, Suggestion is, use POST method
    http.setRequestMethod(HttpConnection.POST);
    //prtMsg(":: Post ::");
    // 2) Send header information - none
    // optional thing


    Thanks And Regards
    Logesh.k

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    37

    Re: How to create Http Connection by specifying the client port?

    Thanks Logesh.k!

    But your code is about specified host on specified port. It is not what I am talking about. OK, Let me make my problem simple,

    I create a simple java HttpConnection app to test Http Digest Authentication which needs two registers. First register reqeust sends out from app, and then receives a 401. Then 2nd register with authentication header sends out. But the problem is these two register need the same port on the client side while the system uses different ports each time. And I don't know how to use one instance of HttpURLConnection to send 2 requests.

    I tried to use socket class but it still cannot let me specify the port on the client side.
    Last edited by SYTDeath; 2007-12-19 at 16:14.

  4. #4
    Registered User
    Join Date
    Oct 2007
    Posts
    24

    Re: How to create Http Connection by specifying the client port?

    It is not possible for client and server connection. you need a specified port for request and response between client and server.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    37

    Re: How to create Http Connection by specifying the client port?

    Which means that it is impossible to test Http Digest Authentication registeration using Java networking programming, isn't it?

    K,

  6. #6
    Registered User
    Join Date
    Oct 2007
    Posts
    24

    Re: How to create Http Connection by specifying the client port?

    yes. It is impossible to register the HTTP Digest Authentication registration thru JAva programming. in the Server Side YOu have get the registration prior before request and response.

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    37

    Re: How to create Http Connection by specifying the client port?

    But I did it anyway

Similar Threads

  1. remote host address(of socket and http connection as well)
    By p_joon in forum Mobile Java General
    Replies: 1
    Last Post: 2007-03-05, 07:04
  2. how to abort or cancel a http connection
    By yavour in forum Mobile Java Networking & Messaging & Security
    Replies: 5
    Last Post: 2007-01-17, 20:26
  3. access points problem with HTTP client api
    By Svat_ in forum Symbian
    Replies: 1
    Last Post: 2006-12-26, 16:19
  4. Close HTTP Connection bug ???
    By cars2004 in forum Mobile Java General
    Replies: 11
    Last Post: 2006-08-26, 01:35
  5. http connection in 6.1 or 7.0 (not 7.0s)
    By lbardone in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2005-04-26, 15:52

Posting Permissions

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