Public Class Httpclientmain {
/**
* @ Param ARGs
*/
Public Static Void Main (string [] ARGs ){
// Todo auto-generated method stub
Socket socket;
Try {
Inetaddress hostadd = Inetaddress. getbyname ( " 192.168.6.5 " );
Socket = New Socket (hostadd, 80 );
Outputstream out = Socket. getoutputstream ();
Inputstream in = Socket. getinputstream ();
Bytearrayoutputstream baos = New Bytearrayoutputstream ();
// Baos. Write ("Data = ABC \ r \ n". getbytes ());
// System. Out. println ("Data lenth:" + baos. tobytearray (). Length );
Byte [] Bytes = ( " GET/HTTP/1.1 \ n " +
" HOST: 192.168.6.5 \ n " +
" Connection: Close \ n " +
" User-Agent: Mozilla/4.0 \ n " +
" Accept-language: ZH-CN \ n " +
" \ N " ). Getbytes ( " UTF-8 " );
Out. Write (bytes );
Out. Flush ();
Byte [] BT = New Byte [ 1024 ];
Inputstreamreader ISR;
Int Len;
Baos. Reset ();
While (Len = In. Read (BT )) >- 1 ){
Baos. Write (BT, 0 , Len );
}
Vector < String > V = Getstartendvalue (baos. tostring (), " \\( " , " \\) " , 0 );
If (V. Size () > 0 ){
System. Out. println (V. firstelement ());
}
Baos. Close ();
In. Close ();
} Catch (Unknownhostexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
} Catch (Ioexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
}
// /<Summary>
// /Obtain the value between the start and end strings.
// /</Summary>
// /<Param name = "str"> string </param>
// /<Param name = "S"> Start </param>
// /<Param name = "E"> end </param>
// /<Param name = "azimuth"> whether the matched content contains the start and end symbols. 0: Not including 1: Include </param>
// /<Returns> </returns>
Public Static Vector < String > Getstartendvalue (string STR, string S, string e, Int Azimuth ){
Pattern pattern;
If (Azimuth = 1 ){
Pattern = Pattern. Compile ( " (? = ( " + S + " ) [. \ S] *? (? <= ( " + E + " )) " );
} Else {
Pattern = Pattern. Compile ( " (? <= ( " + S + " ) [. \ S] *? (? = ( " + E + " )) " );
}
Matcher = Pattern. matcher (STR );
Stringbuffer Buffer = New Stringbuffer ();
Vector < String > Vector = New Vector < String > ();
While (Matcher. Find ()){
Vector. Add (matcher. Group ());
}
Return Vector;
}
}