我有一个非常简单的程序,使用Volley将POST发送到godaddy上的服务器。我在循环中创建了多个请求。该代码适用于前几个请求,但随机给出错误503.有特定模式
我的表只有1列,即userName
我已经到处看了将近两天才弄清楚为什么我会收到错误503.我明白这是因为服务器问题,但我无法弄清楚究竟是什么问题。
这是我的代码
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import java.util.HashMap;
import java.util.Map;
public class MainActivity extends AppCompatActivity {
Button btnInsertData;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnInsertData = (Button) findViewById(R.id.button);
btnInsertData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int counter = 1;
while(counter<=20){
insertData("user" + counter);
counter++;
}
}
});
}
private void insertData(final String data){
String url = "http://...php";
StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.i("Volley response", response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
try{
Log.i("Volley Error", error.getMessage());
}catch(Exception e){
Log.i("Volley Error", "No error found");
}
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> map = new HashMap<String,String>();
map.put("userName",data);
return map;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
requestQueue.add(stringRequest).setShouldCache(false);
Log.i("Status:", "Request created");
}
}
这是我的php文件
include_once './db_functions.php';
$db = new DB_Functions();
$user = $_POST["userName"];
$query = "INSERT INTO testTable (userName) VALUES ('".$user."')";
$result = mysql_query($query);
echo "status_new: ".$result." query: ".$query;
这是我得到的错误
01-03 22:07:37.936 4434-8440/com.qallify.testapplicationvolley E/Volley: [7441] BasicNetwork.performRequest: Unexpected response code 503 for http://....php
答案 0 :(得分:0)
如果您使用的是godaddy的共享托管,则您很可能达到此处所述的资源限制:https://nl.godaddy.com/help/resource-limits-12001