달력

02

« 2012/02 »

  •  
  •  
  •  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  •  
  •  
  •  
HTTP Server로 Client와 연동할 때 간혹 구현에 따라서 HTTP Header와 body 사이에 CRLF가 두 개만 있어야 정상인데, 비정상적으로 CRLF가 두 개 이상일 경우가 발생한다.
이럴 때는 다음과 같은 코드를 넣어 두어 CR, LF에 대한 byte는 skip하고 처리해 주면 된다.

  for ( int k=position; k < this.httpBodyBuffer.length; k++ ) {
   StringBuffer startStringTemp = new StringBuffer();
   startTemp = Integer.toHexString(httpBodyBuffer[k] & 0x000000FF);
   startStringTemp.append((startTemp.length() == 1 ? "0"+startTemp : startTemp));
   
   if ( ("0d".equals(""+startStringTemp)) || ("0a".equals(""+startStringTemp)) ) {
    System.out.println("k = " + k);
   } else {
    position = k;
    System.out.println("HTTP BODY Start position : " + position);
    break;
   }
  }
TAG , ,
Posted by korcslewis