Results 1 to 1 of 1
  1. #1
    Feldsher is offline Member
    Join Date
    Apr 2011
    Rep Power

    Default Making web-client using sockets, empty response after completed authentification.

    Good day,

    Please help me to deal with next problem - I'm making web-client using sockets, and now I take empty response to authenticated content request.

    Authentication response headers are:

    HTTP/1.1 302 Found
    Server: nginx
    Date: Thu, 07 Apr 2011 14:44:09 GMT
    Content-Type: text/html; charset=windows-1251
    Set-Cookie: a=f63bb51c7248ed122; expires=Thu, 07-Apr-2011 12:59:11 GMT; path=/;
    Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    Pragma: no-cach
    location: /user/Feldsher
    Set-Cookie: b=70a0a51c7248ebd12; expires=Thu, 07-Apr-2011 12:59:11 GMT; path=/;
    Set-Cookie: c=783bbec2375335e70; expires=Thu, 07-Apr-2011 12:59:11 GMT; path=/;
    Transfer-Encoding: chunked
    Connection: keep-alive

    I parse it in next way:

    HashMap <String,String> cookies=new HashMap<String,String>();
    BufferedReader reader=new BufferedReader(new InputStreamReader(siteSocket.getInputStream()));
    String ln="";
    while ((ln = reader.readLine()) != null) {
    if (ln.startsWith("location: ")) {
    location=ln.substring("location: ".length());//location is /user/Feldsher
    if(ln.startsWith("Set-Cookie: ")) {
    String ln1 = ln.substring("Set-Cookie: ".length());
    StringTokenizer st = new StringTokenizer(ln1, ";", false);
    while (st.hasMoreTokens()) {
    String chunk = st.nextToken();
    if (chunk.startsWith(" path")
    || chunk.startsWith(" expires")
    || chunk.startsWith(" domain"))
    StringTokenizer st2 = new StringTokenizer(chunk, "=");
    while (st2.hasMoreTokens()) {
    String nameCookie = st2.nextToken();
    String valueCookie = st2.nextToken();
    cookies.put(nameCookie, valueCookie);

    And I request new page in next way:

    to.write("GET "+location+" HTTP/1.1\r\n");
    to.write("Keep-Alive: 300\r\n");
    Iterator cookiesIterator=cookies.entrySet().iterator();
    String cookie="Cookie: ";
    cookie+=cookieTemp.getKey()+"="+cookieTemp.getValu e);
    to.write("Connection: keep-alive\r\n");
    to.write("User-Agent: java/socket\r\n");
    to.write("Accept: */*");
    reader=new BufferedReader(new InputStreamReader(siteSocket.getInputStream()));
    while ((ln = reader.readLine()) != null) {

    In result both "reader" and input stream of socket are empty.
    Which my step is wrong?

    Greatest thanks in advance,
    Last edited by Feldsher; 04-08-2011 at 09:48 AM.

Similar Threads

  1. Client and Server sockets on same machine
    By Yogesh_P in forum Networking
    Replies: 3
    Last Post: 03-28-2011, 04:10 PM
  2. empty response received
    By grashmi13 in forum Networking
    Replies: 6
    Last Post: 09-17-2010, 03:51 AM
  3. empty response received
    By grashmi13 in forum Threads and Synchronization
    Replies: 1
    Last Post: 09-16-2010, 05:58 PM
  4. empty response received
    By grashmi13 in forum Advanced Java
    Replies: 2
    Last Post: 09-16-2010, 05:57 PM

Posting Permissions

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