400是因为错误的语法导致服务器无法理解请求信息。
如果不改成GET请求,需要把地址后面的参数转成hex
我怎么就没看见POST在作怪呢?呵呵
有些手机不管是post还是get都不会有问题,如N82,但是有些手机需要hex一下,如E73
如果还有问题,全部改成get请求!
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();//打印出400
if (HttpConnection.HTTP_OK == httpConn.getResponseCode()) {
}else{
}
如果不改成GET请求,需要把地址后面的参数转成hex
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","*/*");
我怎么就没看见POST在作怪呢?呵呵
有些手机不管是post还是get都不会有问题,如N82,但是有些手机需要hex一下,如E73
如果还有问题,全部改成get请求!