0
我想爲使用PHP的android項目編寫基本賬戶創建。我在腳本上發送電子郵件,密碼和暱稱,並且在數據庫中查詢重複項,並在沒有找到時插入信息。如果我只是運行PHP腳本它工作正常,但不會當我嘗試從Android發佈的東西。下面是代碼:namedValuePairs不被傳遞,而是空的
public String createUser(String email, String pass, String nick) {
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("email", email));
nameValuePairs.add(new BasicNameValuePair("password", pass));
nameValuePairs.add(new BasicNameValuePair("nick", nick));
InputStream is = null;
String reply = null;
try {
HttpClient httpclient = new DefaultHttpClient();
// must store something locally to define this url
// if the url ever changes, gotta make sure droids know without
// requiring an update
HttpPost httppost = new HttpPost(STR_PHP_USER);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
reply = reader.readLine();
Log.e("createUser", "php response is "+reply);
is.close();
} catch (Exception e) {
Log.e("log_tag", "Error in http connection " + e.toString() + " getCreateUserResult_HTTPPost");
}
return reply;
}
腳本應該尼克返回0雙失敗,1電子郵件失敗,失敗2和3的成功。從Android項目我總是得到0,因爲已經有一個用戶在數據庫中的空名和尼克。
也print_r($_GET, true));
結果:
Array
(
)
當我運行Android項目,我得到
Array
(
[email] => [email protected]
[password] => somepassword
[nick] => RandoTheMagnificent
)
如果我從瀏覽器中做到這一點。
任何想法?
我修改了我的腳本,使用POST代替GET的變量,行爲沒有改變。仍然從瀏覽器,但不是應用程序。感謝您的嘗試。 – user800360
你確定它是從瀏覽器中運行的嗎?你如何檢查? – Uhehesh
URL +?+ variablename1 = value1&variablename2 = value2 ....等等。如果我使用不存在的信息進行操作,它會成功創建數據庫中的帳戶並返回3,即成功代碼;如果它存在,它給了我正確的錯誤代碼(0,1或2) – user800360