何らかの理由で、設定した投稿パラメータを非同期タスクに渡すことができません。どんな助けでも大歓迎です。
これがスレッドを呼び出す onClick です。customerInfo は null ではなく、各インデックスには値があることに注意してください。
編集:クライアントとポストの宣言を doInBackground に移動し、余分な不要なスレッドを取り出しました。 EDITED2:明らかに、Webサーバーのサブディレクトリにアクセスし、URLを次のように宣言したとき
http://IP/subDirectory
末尾の「/」がないと、Apache はパラメーターを index.php に渡しません。
@Override
public void onClick(View v) {
new RegisterPost(progress).execute();
}
これが私のdoInBackgroundです
@Override
protected Void doInBackground(Void... voids) {
String[] customerInfo = getRegistrationInfo();
// Post
// Send info to tmiszone
String url = "http://SERVER_ADDRESS/"; // I had to add index.php to my url to get around the issue.
client = new DefaultHttpClient();
post = new HttpPost(url);
// Set post parameters
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("salesCode", customerInfo[0]));
pairs.add(new BasicNameValuePair("firstName", customerInfo[1]));
pairs.add(new BasicNameValuePair("lastName", customerInfo[2]));
try {
post.setEntity(new UrlEncodedFormEntity(pairs));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
// Make connection
try {
response = client.execute(post);
} catch (ClientProtocolException e){
// TODO handle
response = null;
} catch (IOException e) {
// TODO handle
response = null;
} catch (Exception e) {
// TODO handle
response = null;
}
return null;
}
これが私のphpコードです。
<html>
<body>
<?php
error_log("hit by app");
foreach($_POST as $key=>$value){
error_log("// ".$key." ".$value);
}
?>
</body>
</html>
現在、Apache ログに「hit by app」というメッセージが表示されていますが、他には何も表示されていません。そして、私のアプリは、php コードから期待されるように、html タグと body タグだけを含む空の html ページを取得します。