commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Wong Ka Ho Matthew" <matth...@skytelemedia.com>
Subject [HttpClient] Sending Big5 to PHP
Date Wed, 11 Dec 2002 09:20:09 GMT
Hello,

 i want to use the HttpClient to send a Big5 string to a php.

 e.g., i want to send the string "\u738B". this string contains
 only one char, if it's in Big5, it would be coded as 0xA4FD.
 (Big5 uses 2 bytes to represent a Chinese character, pls visit
 http://ash.jp/code/cn/big5tbl.htm for reference)

 the querystring should look like: message=%A4%FD

 the problem is, i dunno how to make the querystring = %A4%FD.

 it should be quite simple, right? but i really have no idea...

 --- cut ---

  String    message = "\u738b";
  GetMethod get     = new GetMethod();

  try {
          Charset        big5Charset         =
Charset.forName("Big5-HKSCS");
          CharsetEncoder big5CharsetEncoder  = big5Charset.newEncoder();
          ByteBuffer     bbuf                =
big5CharsetEncoder.encode(CharBuffer.wrap(message));

          // what i should do here?
          // message = new String(bbuf.array(), "ISO-8859-1");

  } catch (Exception e) {
          logger.error(e);
  }

  NameValuePair nv[] = {new NameValuePair("message", message)};

  get.setQueryString(nv);

  System.out.println("Query String: " + get.getQueryString());

 --- cut ---

 i have try to use a for loop to print the bbuf:

  byte[] b = bbuf.array();

  for (int i=0; i<b.length; i++) {
   System.out.println("-> " + Integer.toHexString(new
Byte(b[i]).intValue()));
  }

 and i got:

  -> ffffffa4
  -> fffffffd

 seems it's very close to what i wanna have... but, is it should
 be a4 and fd, instead of ffffffa4 and fffffffd?

 ...

 thanks in advance.

---
matt


Mime
View raw message