私のアプリケーションは、いくつかAsynctask
の異なるを介してサーバーに呼び出しを行い、データを2回プルし、最後にJSONArray
POSTを介して送信します。
正常に動作していましたが、最近停止し、変更はありませんでした。これが必要な情報だけを持っAsyncTask
たPOST
私のものです:JSONArray
更新されたJAVA
String inString;
JSONObject realjObject;
JSONArray compJArray;
int completeCount = 0;
URL url;
@Override
protected Void doInBackground(JSONArray... jsonArray) {
if(jsonArray.length > 0) {
compJArray = jsonArray[0];
}
completeCount = compJArray.length();
//String url_select = "http://www.myDomain.com/db/completedSurvey.php";
HttpResponse response;
for (int i = 0; i < completeCount; i++) {
try {
realjObject = compJArray.getJSONObject(i);
Log.i("realjObject", realjObject.toString());
try {
url = new URL("http://www.myDomain.com/db/completedSurvey.php");
HttpPost httpPost = new HttpPost(url.toURI());
HttpClient httpClient = new DefaultHttpClient();
httpPost.setEntity(new StringEntity(realjObject.toString(), "UTF-8"));
httpPost.setHeader(HTTP.DEFAULT_CONTENT_TYPE, "application/json");
response = (HttpResponse) httpClient.execute(httpPost);
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
StringBuilder builder = new StringBuilder();
for (String line = null; (line = reader.readLine()) != null;) {
builder.append(line).append("\n");
}
inString = builder.toString();
Log.w("RESPONSE", inString);
} catch (UnsupportedEncodingException e1) { Log.e("UnsupportedEncodingException", e1.toString());
} catch (ClientProtocolException e2) { Log.e("ClientProtocolException", e2.toString());
} catch (IllegalStateException e3) { Log.e("IllegalStateException", e3.toString());
} catch (IOException e4) { Log.e("IOException", e4.toString());
} catch (URISyntaxException e) {Log.e("URISyntaxException", "" + e.getMessage());
}
} catch (JSONException e) { Log.e("doInBackground", "JSONException: " + e.getMessage());
}
}
return null;
}
そして、これが私がコードを受け取る方法です、PHP-サーバー側:
require("../logger/logging.class.php");
$genLog->lwrite("Is Android accessing this url?");
$json = file_get_contents('php://input');
$genLog->lwrite($json);
if ($json) {
// Parse JSONArray, was working properly
}
ブラウザからURLにアクセスすると、ログは完全に正常に書き込まれますが、アプリケーションの実行時に何も書き込まれません。ですべての出力をテストしましたがAsyncTask
、すべてが正常に機能しているようです。
LogCat
realjObject
(www.jsonlint.comで確認済み)の出力:
{
"Notes": "null",
"SurveyPhoto": "null",
"id": 2,
"siteNotes": "",
"loc_id": 1,
"sign_type": "FREESTANDING SIGN",
"Lighting": 0,
"AdditionalService": 0,
"view_id": 2,
"survey_order": 1
}
編集
require("../logger/logging.class.php");
と競合する可能性があると考え始めたばかりですが$json = file_get_contents('php://input');
、すべてのログをコメントアウトし、行が必要であり、それでも何も実行されていません。
デバイスにインターネット接続があり、このMySQLデータベースとの接続が確立されているか、を送信できませんJSONArray
。
テストデバイス:Android4.0.1を実行しているSamsungGalaxy Tab 10.1 Gen 1
編集2
を修正しInputStream
て応答を返し、次の404および406応答を取得しました。
12-05 09:31:39.345: W/RESPONSE(19023): <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
12-05 09:31:39.345: W/RESPONSE(19023): <html><head>
12-05 09:31:39.345: W/RESPONSE(19023): <title>406 Not Acceptable</title>
12-05 09:31:39.345: W/RESPONSE(19023): </head><body>
12-05 09:31:39.345: W/RESPONSE(19023): <h1>Not Acceptable</h1>
12-05 09:31:39.345: W/RESPONSE(19023): <p>An appropriate representation of the requested resource /db/completeSurvey.php could not be found on this server.</p>
12-05 09:31:39.345: W/RESPONSE(19023): <p>Additionally, a 404 Not Found
12-05 09:31:39.345: W/RESPONSE(19023): error was encountered while trying to use an ErrorDocument to handle the request.</p>
12-05 09:31:39.345: W/RESPONSE(19023): <hr>
12-05 09:31:39.345: W/RESPONSE(19023): <address>Apache Server at www.myDomain.com Port 80</address>
12-05 09:31:39.345: W/RESPONSE(19023): </body></html>
突然これを引き起こす可能性があるのは何ですか?
編集3-トラブルシューティングのために私が取った最近の手順:
- 私は私たちのウェブホストに連絡しました、そして彼らは彼らの側のすべてが大丈夫だと私に言っています。サーバーログ(error_log)はエラーを表示しません
- 上記のJavaを少し変更して、応答の戻り値を表示するとともに、の
URL
代わりにクラスを使用するように変更しString
ましたnew HttpPost(url.toURI());
。LogCatは、ブラウザにコピーして貼り付けられた正しいドメインを表示し、正常に機能します。 - URLを別のファイルに変更し、
/db/completeSurvey.php
内容を新しいファイルに配置しました。上記と同じ404/406応答です。 fwrite
上記と同じ404/406応答である、ログページへの呼び出しのみを含む別の新しいphpファイルを作成しました。- ルートドメイン「http://www.myDomain.com」に転送しました。上記と同じ404/406応答です。
私はそれがデバイスか私のコードのどちらかでなければならないと考え始めています。