错误:";你的请求超时了。请重试该请求。”;用Android和PHP编程

错误:";你的请求超时了。请重试该请求。”;用Android和PHP编程,php,android,hosting,Php,Android,Hosting,我有一个Android应用程序,它可以与托管提供商上的服务器通信。 此应用程序发送http请求php脚本检索请求并在数据库中执行操作。 我更改了数据库并调整了程序,现在服务器上出现错误:“您的请求超时。请重试请求。” 当我在像firefox或chrome这样的浏览器中执行http命令时,该命令被正确执行,而在执行代码时会出现错误 这不是脚本或http请求,因此我根本看不到它会出现在哪里。你能帮助我吗?多谢各位 这里有Android代码: public class ConnexionSQL ext

我有一个Android应用程序,它可以与托管提供商上的服务器通信。 此应用程序发送http请求php脚本检索请求并在数据库中执行操作。 我更改了数据库并调整了程序,现在服务器上出现错误:“您的请求超时。请重试请求。”

当我在像firefox或chrome这样的浏览器中执行http命令时,该命令被正确执行,而在执行代码时会出现错误

这不是脚本或http请求,因此我根本看不到它会出现在哪里。你能帮助我吗?多谢各位

这里有Android代码:

public class ConnexionSQL extends AsyncTask<Object,Void, ArrayList<String[]> > {


private static ArrayList<String[]> lesMessagesEtDate;
private String mydataFromHMI;
private String myFichierPHPbase;
private ProgressDialog pd;
private String[] splitData;
private boolean isProblemConnexion;

public ConnexionSQL(Activity activity) {

    pd = new ProgressDialog(activity);
    lesMessagesEtDate = new ArrayList<String[]>();
    mydataFromHMI = "";
    myFichierPHPbase="";
    isProblemConnexion = false;
}


protected ArrayList<String[]> doInBackground(Object... parametres) {
    Object[] tabArg = parametres;
    ArrayList<String[]>  messagesDateEtLocalisation = new ArrayList<String[]>();
    pd.show();

     if (((String)tabArg[3]).equalsIgnoreCase("insert")){

         insertIntoBD((String)tabArg[0], (Context)tabArg[1], (String)tabArg[2]);

     }else if(((String)tabArg[3]).equalsIgnoreCase("connect")){

         messagesDateEtLocalisation = ConnexionBD((String)tabArg[0], (Context)tabArg[1], (String)tabArg[2]);
     }
    return messagesDateEtLocalisation;
}


protected void onPreExecute() {
    pd.setMessage("Chargement en cours");
    pd.show();
}


protected void onProgressUpdate(){
    pd.setMessage("Chargement en cours");
    pd.show();
}

protected void onPostExecute(ArrayList<String[]> array)
{
    pd.setMessage("Le chargement se termine");
    pd.dismiss();     

}

public void insertIntoBD(String dataFromHMI, Context context, String FichierPHPbase){


    mydataFromHMI = dataFromHMI;
    myFichierPHPbase = FichierPHPbase;



    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

    try{
        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
        HttpProtocolParams.setUseExpectContinue(params, false);  
        HttpConnectionParams.setConnectionTimeout(params, 10000);
        HttpConnectionParams.setSoTimeout(params, 10000);
        ConnManagerParams.setMaxTotalConnections(params, 1000);
        ConnManagerParams.setTimeout(params, 30000);

        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(), 80));
        registry.register(new Scheme("https",PlainSocketFactory.getSocketFactory(), 80));
        ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry);
        HttpClient httpclient = new DefaultHttpClient(manager, params);

        HttpPost httppost = new HttpPost("http://routeslibre.fr/"+ myFichierPHPbase + "?variable=" + mydataFromHMI);
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        httpclient.execute(httppost);


    }
    catch(Exception e){
        Log.i("taghttppost",""+e.toString());
        isProblemConnexion = true;
    }

}



public ArrayList<String[]> ConnexionBD(String dataFromHMI, Context context,String FichierPHPbase) {

    mydataFromHMI = dataFromHMI;
    myFichierPHPbase = FichierPHPbase;

    String result = null;
    InputStream is = null;
    JSONObject json_data=null;
    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

    try{
        //commandes httpClient

        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
        HttpProtocolParams.setUseExpectContinue(params, false);  
        HttpConnectionParams.setConnectionTimeout(params, 10000);
        HttpConnectionParams.setSoTimeout(params, 10000);
        ConnManagerParams.setMaxTotalConnections(params, 1000);
        ConnManagerParams.setTimeout(params, 30000);

        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(), 80));
        registry.register(new Scheme("https",PlainSocketFactory.getSocketFactory(), 80));
        ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry);


        HttpClient httpclient = new DefaultHttpClient(manager, params);             

        GestionStrings gestionString = new GestionStrings();
        splitData = mydataFromHMI.split(";;;");
        mydataFromHMI = gestionString.blancTraitement(splitData[0]) 
                + ";;;" 
                + gestionString.blancTraitement(splitData[1]) 
                + ";;;";

        HttpPost httppost = new HttpPost("http://routeslibre.fr/"+ myFichierPHPbase + "?variable=" + mydataFromHMI);
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        is = entity.getContent();
    }
    catch(Exception e){
        Log.i("taghttppost",""+e.toString());
        isProblemConnexion = true;
    }


    //conversion de la réponse en chaine de caractère
    try
    {
        BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"));

        StringBuilder sb  = new StringBuilder();

        String line = null;

        while ((line = reader.readLine()) != null) 
        {
            sb.append(line + "\n");
        }

        is.close();

        result = sb.toString();
        if (result.startsWith("<html>"))
        {
            isProblemConnexion = true;
        }
    }
    catch(Exception e)
    {
        Log.i("tagconvertstr",""+e.toString());
        isProblemConnexion = true;
    }
    //recuperation des donnees json
    try{
        JSONArray jArray = new JSONArray(result);

        for(int i=0;i<jArray.length();i++)
        {

            json_data = jArray.getJSONObject(i);
            String[] messageEtDate = new String[2];
            messageEtDate[0] = json_data.getString("message");
            messageEtDate[1] = json_data.getString("date");
            lesMessagesEtDate.add(messageEtDate);


        }
        //setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, lesMessages));
    }
    catch(JSONException e){
        Log.i("tagjsonexp",""+e.toString());
        isProblemConnexion = true;
    } catch (ParseException e) {
        Log.i("tagjsonpars",""+e.toString());
        isProblemConnexion = true;
    }
    if (isProblemConnexion){

        lesMessagesEtDate = new ArrayList<String[]>();
        lesMessagesEtDate.add(new String[]{"connexion_error_1234"});
        isProblemConnexion = false;
    }
    return lesMessagesEtDate;
}
当我在“is.close()”行上停止调试器时,值“db”等于“
您的请求超时。请重试该请求。”

如果你不介意的话,你能给我一个技巧,一个找出错误的方法吗

我把这一行放在代码中:
int test=response.getStatusLine().getStatusCode()

测试值为408(如网站中所述),这意味着我的主机提供商有错误。但是为什么当我放入http请求时,从代码中检索:value of
http://routeslibre.fr/“+Myficherpbase+”?变量=“+mydataFromHMI
当我将其作为chrome或firefox放入web客户端时,我的php脚本非常有效。。。我不明白

有了这段代码,它就不能完美地工作:有时它能工作,有时不能。当调试器设置为执行操作时,会出现异常,其值仅为“null”。你能帮我吗

以下是无法找到的代码:

HttpGet httpGet = new HttpGet(url);
HttpParams httpParameters = new BasicHttpParams();
// Set the timeout in milliseconds until a connection is established.
// The default value is zero, that means the timeout is not used. 
int timeoutConnection = 3000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
// Set the default socket timeout (SO_TIMEOUT) 
// in milliseconds which is the timeout for waiting for data.
int timeoutSocket = 5000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);

DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpResponse response = httpClient.execute(httpGet);
我找到了一个解决方案,我循环执行代码,直到我收到一个请求(从服务器检索的状态等于200),或者,如果请求没有提供任何结果,则启动一个错误。 以下是我的解决方案:

        String httpRequest = new String("http://routeslibre.fr/"+ myFichierPHPbase + "?variable=" + mydataFromHMI);
        HttpPost request = new HttpPost(httpRequest); 
        HttpParams httpParameters = new BasicHttpParams();
        HttpProtocolParams.setVersion(httpParameters, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(httpParameters, HTTP.UTF_8);

        DefaultHttpClient httpclient = new DefaultHttpClient(httpParameters);

        HttpResponse response = null;
        for(int i= 0; i < 30; i++){
            response = httpclient.execute(request);
            if (response.getStatusLine().getStatusCode() == 200){
                break;
            }else if (i == 29){

                //ERROR CODE
            }
        }
String httpRequest=新字符串(“http://routeslibre.fr/“+myfichierpbase+”?变量=“+mydataFromHMI);
HttpPost请求=新的HttpPost(httpRequest);
HttpParams httpParameters=新的BasicHttpParams();
setVersion(httpParameters,HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(httpParameters,HTTP.UTF_8);
DefaultHttpClient httpclient=新的DefaultHttpClient(httpParameters);
HttpResponse响应=null;
对于(int i=0;i<30;i++){
response=httpclient.execute(请求);
if(response.getStatusLine().getStatusCode()==200){
打破
}否则如果(i==29){
//错误代码
}
}

使用此代码,这些代码并不完美:有时它有效,有时则无效。当调试器设置为执行操作时,会出现异常,其值仅为“null”。你能帮我吗

以下是无法找到的代码:

HttpGet httpGet = new HttpGet(url);
HttpParams httpParameters = new BasicHttpParams();
// Set the timeout in milliseconds until a connection is established.
// The default value is zero, that means the timeout is not used. 
int timeoutConnection = 3000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
// Set the default socket timeout (SO_TIMEOUT) 
// in milliseconds which is the timeout for waiting for data.
int timeoutSocket = 5000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);

DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpResponse response = httpClient.execute(httpGet);
我找到了一个解决方案,我循环执行代码,直到我收到一个请求(从服务器检索的状态等于200),或者,如果请求没有提供任何结果,则启动一个错误。 以下是我的解决方案:

        String httpRequest = new String("http://routeslibre.fr/"+ myFichierPHPbase + "?variable=" + mydataFromHMI);
        HttpPost request = new HttpPost(httpRequest); 
        HttpParams httpParameters = new BasicHttpParams();
        HttpProtocolParams.setVersion(httpParameters, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(httpParameters, HTTP.UTF_8);

        DefaultHttpClient httpclient = new DefaultHttpClient(httpParameters);

        HttpResponse response = null;
        for(int i= 0; i < 30; i++){
            response = httpclient.execute(request);
            if (response.getStatusLine().getStatusCode() == 200){
                break;
            }else if (i == 29){

                //ERROR CODE
            }
        }
String httpRequest=新字符串(“http://routeslibre.fr/“+myfichierpbase+”?变量=“+mydataFromHMI);
HttpPost请求=新的HttpPost(httpRequest);
HttpParams httpParameters=新的BasicHttpParams();
setVersion(httpParameters,HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(httpParameters,HTTP.UTF_8);
DefaultHttpClient httpclient=新的DefaultHttpClient(httpParameters);
HttpResponse响应=null;
对于(int i=0;i<30;i++){
response=httpclient.execute(请求);
if(response.getStatusLine().getStatusCode()==200){
打破
}否则如果(i==29){
//错误代码
}
}