if(this.iConnType == Constant.CONNECTION_CMNET)//CMNET
{
this.httpConn = (HttpConnection)Connector.open(this.strAllAddress,Connector.READ_WRITE, true);
////strAllAddress = "http://ip+port+dir";
this.httpConn.setRequestMethod(HttpConnection.POST);
this.outputStream = this.httpConn.openOutputStream();
this.outputStream.write(request.getContent());
this.inputStream = this.httpConn.openInputStream();
response = this.readResponse(this.inputStream);
if(response == null)
{
// 服务器返回数据错误, 即网络IO错误
bError = true;
}
}
else // CMWAP
{
this.httpConn = (HttpConnection)Connector.open("http://10.0.0.172:80" +
this.strAddress, Connector.READ_WRITE, true);
this.httpConn.setRequestMethod(HttpConnection.POST);
httpConn.setRequestProperty("Accept", "*/*");
httpConn.setRequestProperty("X-Online-Host", this.strIP);
//for example,this.strIP = "127.0.0.1:8080";
this.outputStream = this.httpConn.openOutputStream();
this.outputStream.write(request.getContent());
this.inputStream = this.httpConn.openInputStream();
response = this.readResponse(this.inputStream);
if(response == null)
{
// 服务器返回数据错误, 即网络IO错误
bError = true;
}
}
本文介绍了一种根据不同的网络连接类型(CMNET和CMWAP)进行HTTP请求的方法。通过判断网络类型来选择合适的服务器地址,并使用HttpConnection进行POST请求,最后读取服务器响应。
668

被折叠的 条评论
为什么被折叠?



