我遇到一个问题。 我使用Android Volley调用Python服务器,但它将调用两次。如何让它只运行一次?
症状:它将两次调用callphone.py文件。
Android代码:
url = http://xxx.xxx.xxx.xxx:8080/callphone.py
public static ArrayList<Bot> bots = new ArrayList<Bot>();
python服务器代码:
private void request_z(String url) {
final RequestQueue requestQueue = Volley.newRequestQueue(this);
final StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>(){
@Override
public void onResponse(String response) {
//textView.setText("Response is: " + response.substring(0, 500));
requestQueue.stop();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
textView.setText("That didn't work!");
requestQueue.stop();
}
});
requestQueue.add(stringRequest);
服务器日志 Microsoft Windows [版本6.1.7601] 版权所有(c)2009 Microsoft Corporation。保留所有权利。
import BaseHTTPServer
import CGIHTTPServer
import cgitb; cgitb.enable()
server = BaseHTTPServer.HTTPServer
handler = CGIHTTPServer.CGIHTTPRequestHandler
server_address = ("", 8080)
handler.cgi_directories = ["/"]
httpd = server(server_address, handler)
httpd.serve_forever()