试图让vars发送到服务器的url。 (脚本可以通过手动链接找到)。变量被拾取并显示在日志中,但在我显示的代码部分中,url不调用脚本:String urlString = SERVER + this.getString(R.string.login_details_url); (顺便说一句,php文件名拼写正确的是在其他工作活动中调用的常量)。Android代码中的扭曲Java方法需要良好的眼球
我认为这可能是一个方法设置的问题。并且似乎有来自服务器的有效响应,其在最后占据了激活的成功吐司。这里缺少什么?
感谢
private void acctinfo(String username, String email, String password, String usertype, String over35, String userid) {
Log.d(DEBUG_TAG, "AcctInfo() entered:" + username + email + password + usertype + over35 + userid); /// These vars show up in logs
try
{
sendAcctInfoToServer(this, username, email, password, usertype, over35, userid);
}
catch(Exception e)
{
e.printStackTrace();
Log.d(DEBUG_TAG, "sendAcctInfoToServer error " , e);
Toast.makeText(mContext, "Failed to Subit New Info", Toast.LENGTH_SHORT).show();
}
}
private void sendAcctInfoToServer(Context context, String username, String email, String password, String usertype, String over35, String userid) throws Exception
{
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
String urlString = SERVER + this.getString(R.string.login_details_url);
urlString = urlString + "?" + USEREMAIL_VAR + "=" + email;
urlString = urlString + "&" + PASSWORD_VAR + "=" + password;
urlString = urlString + "&" + USERNAME_VAR + "=" + username;
urlString = urlString + "&" + USERID_VAR + "=" + userid;
urlString = urlString + "&" + USERTYPE_VAR + "=" + usertype;
urlString = urlString + "&" + OVER35_VAR + "=" + over35;
urlString = urlString+ "&change_acct=1";
HttpPost httppost = new HttpPost(urlString); //////This url does not get sent
HttpResponse response =httpclient.execute(httppost);
// Check if server response is valid
String result = null;
StatusLine status = response.getStatusLine();
Log.d(DEBUG_TAG, " AcctInfo response.getStatusLine() " + status.getStatusCode());
if (status.getStatusCode() != HttpURLConnection.HTTP_OK) {
result = "Invalid response from server, status code=" + status.toString();
// Failed - so throw
throw new Exception("Please try again" + result); //TODO external string, remove details of error
}
else {
//toast
Toast.makeText(mContext, getString(R.string.toast_acct_info_saved), Toast.LENGTH_SHORT).show(); /// this success toast appears but no vars, of course, are passed to script
finish();
}
}
谢谢你的回复,吕克。有趣的是,我发布的这部分代码在Login.java中是“镜像的”,并且没有任何问题。为什么它在这个文件AcctInfo.java中不起作用,这很奇怪。思考? – artworthy 2011-03-14 18:44:05