Php 应用程序突然停止向数据库投递,返回状态代码406

Php 应用程序突然停止向数据库投递,返回状态代码406,php,android,arrays,Php,Android,Arrays,我的应用程序通过两个不同的Asynctask调用我们的服务器,它两次提取数据,最后通过POST发送JSONArray 它一直工作正常,但最近停止,没有进行任何更改。这是我的AsyncTask到POSTaJSONArray的任务,只包含必要的信息: 更新的JAVA String inString; JSONObject realjObject; JSONArray compJArray; int completeCount = 0; URL url; @Override protected Voi

我的应用程序通过两个不同的
Asynctask
调用我们的服务器,它两次提取数据,最后通过POST发送
JSONArray

它一直工作正常,但最近停止,没有进行任何更改。这是我的
AsyncTask
POST
a
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;
}
如果我通过浏览器访问url,我的日志写得非常好,但是在运行应用程序时没有写入任何内容。我已经测试了
AsyncTask
中的所有输出,似乎一切正常


LogCat
realjObject的输出(在www.jsonlint.com上验证):


编辑

我刚开始认为我的
需要(“../logger/logging.class.php”)
可能与
$json=file\u get\u contents('php://input');,但我只是注释掉了我所有的日志记录并需要行,它仍然没有做任何事情

设备已连接到internet,并且已与此MySQL数据库建立连接,否则我将无法提交
JSONArray

测试设备:运行Android 4.0.1的三星Galaxy 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>
12-0509:31:39.345:W/回复(19023):
12-05 09:31:39.345:W/回复(19023):
12-05 09:31:39.345:W/回复(19023):406不可接受
12-05 09:31:39.345:W/回复(19023):
12-05 09:31:39.345:W/回复(19023):不可接受
12-05 09:31:39.345:W/RESPONSE(19023):在此服务器上找不到请求资源的适当表示/db/completeSurvey.php

12-05 09:31:39.345:W/回复(19023):此外,未找到404 12-05 09:31:39.345:W/RESPONSE(19023):尝试使用ErrorDocument处理请求时遇到错误

12-05 09:31:39.345:W/回复(19023):
12-05 09:31:39.345:W/RESPONSE(19023):Apache服务器位于www.myDomain.com端口80 12-05 09:31:39.345:W/回复(19023):
什么会突然导致这种情况

编辑3-我最近采取的故障排除步骤:

  • 我已经联系了我们的网络主机,他们告诉我他们这边的一切都很好。 服务器日志(错误日志)未显示任何错误
  • 我稍微更改了上面的Java以显示我的响应返回,并更改为使用
    URL
    类,而不是
    String
    用于
    新的HttpPost(URL.toURI())。LogCat显示正确的域,复制并粘贴到浏览器中,工作正常
  • 我已将URL更改为另一个文件,并将
    /db/completeSurvey.php
    内容放入新文件中,与上面的404/406响应相同
  • 我创建了另一个新的php文件,其中只包含一个
    fwrite
    来记录页面调用,与上面的404/406响应相同
  • 我指向我们的根域,”http://www.myDomain.com“,与上述404/406响应相同

  • 我开始认为它要么是设备,要么是我的代码。

    你想用这行代码inString=in.toString()做什么?您正在
    InputStream
    上调用
    toString()
    ,它不会返回响应数据

    请尝试以下代码来读取json:

    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();
    
    我联系了我们的网络主机(超越主机),并给了他们以下消息:

    406不可接受

    在此服务器上找不到请求的资源/db/completedSurvey.php的适当表示形式

    此外,尝试使用ErrorDocument处理请求时遇到404 Not Found错误

    位于www.myDomain.com端口80的Apache服务器

    起初,他们说我需要编写更多的日志代码来确定原因,因为这不是他们的目的

    最终我被送到了技术支持二级,那里的人马上给了我答案:


    解决方案:

    超越科技:
    “这是由于脚本与mod_security中的规则匹配。我仅为该文件禁用了此规则。”


    我现在没有用它做任何事情,最终我会返回一个成功与否的响应代码。我的
    AsyncTask
    未从工作状态更改为不工作状态。这不是问题。还有一件事可以尝试。。尝试通过添加浏览器正在发送的所有标头来复制浏览器。。。可以通过转到以下URL来检查浏览器标题。。只需检查服务器是否允许来自浏览器的请求,而不允许来自应用程序的请求…请尝试以下操作:在localhost或Google App Engine上托管您的页面。。看看你能不能找到那个。。。如果这样做有效,那么问题可能出在服务器提供商身上……我发现这是一个与
    mod_security
    中的规则相匹配的脚本,我让他们禁用了,现在一切又正常了。很抱歉把你拖过来了。如果您想将答案更改为与我发现的内容相关的内容,那么我会将其标记为已接受。我建议您将您的解决方案发布为答案并接受,以便其他人将来可以从中受益。。
    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>
    
    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();