【发布时间】:2011-12-01 15:13:09
【问题描述】:
我正在开发一个应用程序以使用 httpconnection 将一些数据获取到 .Net Web 服务。当我在本地托管 web 服务并使用 Eclipse 模拟器对其进行测试时,代码工作正常,但是当我在公共部署服务器上托管 web 服务并将黑莓应用程序打包到我的设备时,我得到的是一个响应代码 500。请有人可以给我一个线索、答案或解决方案来解决这个问题?
以下是我使用的代码:
String URL = WebServiceURL+"/Login"+getConnectionParameter();
public static String getConnectionParameter() {
String ConnectionParameter ="" ;
if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
// Connected to a WiFi access point
ConnectionParameter = ";interface=wifi";
} else {
int coverageStatus = CoverageInfo.getCoverageStatus();
ServiceRecord record = getWAP2ServiceRecord();
if (record != null && (coverageStatus & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT) {
// Have network coverage and a WAP 2.0 service book record
ConnectionParameter = ";deviceside=true;ConnectionUID="+ record.getUid();
} else if ((coverageStatus & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS) {
// Have an MDS service book and network coverage
ConnectionParameter = ";deviceside=false";
} else if ((coverageStatus & CoverageInfo.COVERAGE_DIRECT) == CoverageInfo.COVERAGE_DIRECT) {
// Have network coverage but no WAP 2.0 service book record
ConnectionParameter = ";deviceside=true";
}
}
return ConnectionParameter;
}
URLEncodedPostData oPostData = new URLEncodedPostData(
URLEncodedPostData.DEFAULT_CHARSET, false);
oPostData.append("username",username.getText());
oPostData.append("compressedpicture",HomeScreen.convertByteArrayToString(imageArray));
oPostData.append("email",email.getText());
oPostData.append("password",password.getText());
oPostData.append("pin",pin.getText());
oPostData.append("extension",extension);
String URL = MYAPP.WebServiceURL+"/SignUp"+MYAPP.getConnectionParameter();
String result = HomeScreen.postinfo(URL,oPostData);
Dialog.inform(result);
if(result.indexOf("success")!= -1){
Dialog.inform("You Have just sign up. Congratulations.");
}else{
Dialog.inform("There is an issue registering you");
}
public static String postinfo(String _URL,URLEncodedPostData _PostData) {
String result = "";
try {
HttpConnection conn = (HttpConnection) Connector.open(_URL,
Connector.READ_WRITE);
if (_PostData != null) {
conn.setRequestMethod(HttpConnection.POST);
conn.setRequestProperty("Content-type",
"application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length",
Integer.toString(_PostData.size()));
OutputStream strmOut = conn.openOutputStream();
strmOut.write(_PostData.getBytes());
strmOut.close();
} else {
conn.setRequestMethod(HttpConnection.GET);
}
int responseCode = conn.getResponseCode();
if (responseCode == HttpConnection.HTTP_OK) {
InputStream data = conn.openInputStream();
StringBuffer raw = new StringBuffer();
byte[] buf = new byte[4096];
int nRead = data.read(buf);
while (nRead > 0) {
raw.append(new String(buf, 0, nRead));
nRead = data.read(buf);
}
result = raw.toString();
//Dialog.alert("Result:" + raw.toString());
//_Dest.updateDestination(raw.toString());
} else {
_Dest.updateDestination("responseCode="
+ Integer.toString(responseCode));
result = "responseCode= "+ Integer.toString(responseCode);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
//_Dest.updateDestination("Exception:" + e.toString());
result = "Exception:" + e.toString();
}
return result;
}
【问题讨论】:
-
你有服务器响应,所以这意味着 BB 网络工作正常。我建议检查服务器日志以了解问题原因。
-
感谢 Arhimed 目前正在处理该问题
-
我的 IIS 服务器上有以下日志。我不知道这意味着什么:2011-11-29 16:13:41 myIP POST /myapp/WebService1.asmx/Login - 80 - IP - 500 0 0 218
-
除了服务器将您的 POST 请求发送到指定的 url、端口和指定的 IP 之外,这并不能说明什么。
标签: java blackberry blackberry-jde