j2me代理连接返回码总是400的问题
400是因为错误的语法导致服务器无法理解请求信息。
Consts.debug="启用http代理连接";httpConn = (HttpConnection) Connector.open("http://10.0.0.172:80/kjava.portal?action=xxx");httpConn.setRequestMethod(HttpConnection.GET);//需要改成GET请求httpConn.setRequestProperty("X-Online-Host", "wap.5bingo.cn");httpConn.setRequestProperty("Connection", "Keep-Alive");httpConn.setRequestProperty("Accept","*/*");Consts.debug="连接状态:"+httpConn.getResponseCode();//打印出400if (HttpConnection.HTTP_OK == httpConn.getResponseCode()) {}else{}
public static String bin2hex(String bin) throws UnsupportedEncodingException {char[] digital = "0A1B2C3D4E5F6789".toCharArray();StringBuffer sb = new StringBuffer("");byte[] bs = bin.getBytes("utf-8");int bit;for (int i = 0; i < bs.length; i++) {bit = (bs[i] & 0x0f0) >> 4;sb.append(digital[bit]);bit = bs[i] & 0x0f;sb.append(digital[bit]);}return sb.toString();}
String hex=bin2hex("action=xxx");httpConn = (HttpConnection) Connector.open("http://10.0.0.172:80/kjava.portal?"+hex);httpConn.setRequestMethod(HttpConnection.POST);//需要改成POST请求httpConn.setRequestProperty("X-Online-Host", "wap.5bingo.cn");httpConn.setRequestProperty("Connection", "Keep-Alive");httpConn.setRequestProperty("Accept","*/*");