使用cmwap方式访问网络,返回的数据是乱码?
在J2ME中,使用cmwap方式通过10.0.0.172访问网络,网络连接是正常的,返回值是200。但是读取inputstream数据,返回的数据是乱码?如下;
jl°ZCache-Control max-age=0W°Cache-control no-cacheW°ZCache-Control must-revalidate(后面还有类似的数据)
使用的是Nokia 6670的手机,好像曾经做测试的过程中选择访问接入点的时候,选择了GPRS方式,返回的数据是乱码,但是后来改选成cmwap方式,数据也一直不对了。不知与这个有没有关系?
另外就是,使用之前能够成功联网和读取数据的程序(之前这个功能已经调试正常),现在做测试都不能成功,返回的都是类似的乱码?是不是移动的网关出了问题?
请问高手,是什么原因造成的?怎么解决?多谢!!!
同时,将代码附在下面:
程序如下:
Form resultsForm = new Form("Results");
mDisplay.setCurrent(resultsForm);
HttpConnection httpconnection;
InputStream inputstream;
httpconnection = null;
inputstream = null;
try {
String url = "pams/s.do?p=501&j=l&c=5114&b=5098";
httpconnection = (HttpConnection)Connector.open("http://10.0.0.172/" + url);
httpconnection.setRequestProperty("X-Onlie-Host","http://wap.beijing2008.cn");
httpconnection.setRequestMethod("GET");
httpconnection.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.0");
resultsForm.append("Response=" + httpconnection.getResponseMessage());
if (httpconnection.getResponseCode() == 200)
{
resultsForm.append("connect success!");
// Retrieve the response.
inputstream = httpconnection.openInputStream();
long actualLength = httpconnection.getLength();
byte[] raw = new byte[(int)actualLength];
int readLength = inputstream.read(raw);
String type = httpconnection.getType();
String message = new String(raw, 0, readLength);//, "UTF-8");
resultsForm.append("type=<" + type + ">" + "\n" +
"actualLength=<" + actualLength + ">" + "\n" +
"lenght=<" + readLength + ">" + "\n" +
"msg=<" + message + ">");
}
}
catch (Exception _ex) { }
以上代码在我的Nokia 6670手机上运行返回的是乱码。使用UTF-8方式也试过了,结果还是乱码,数据不正确。
请各位帮忙,多谢了!