【发布时间】:2011-03-14 18:06:38
【问题描述】:
试图在 url 中将 vars 发送到服务器。 (脚本可以通过手动 url 找到)。变量被拾取并显示在日志中,但在我在这里显示的代码部分中,url 没有调用脚本: String urlString = SERVER + this.getString(R.string.login_details_url); (顺便说一句,在其他工作活动中调用的常量中,php 文件名拼写正确)。
我认为这可能是方法设置方式的问题。并且似乎有来自服务器的有效响应,这说明了最后激活的成功敬酒。这里缺少什么?
谢谢
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();
}
}
【问题讨论】: