我最近写了一个带有排球的Android应用来做http请求, 起初,我使用本地主机作为服务器,它工作得很好。 但是,当我将node.js代码移动到heroku服务器时,我的应用程序通常会出现超时错误。 来自heroku的日志,如
2016-04-23T00:59:01.653405+00:00 heroku[router]: at=info method=POST path="/ispassword" host=lit-island-38801.herokuapp.com request_id=1273b9e7-6632-4117-b68f-5d7d8eb83b52 fwd="152.3.43.156" dyno=web.1 connect=1ms service=27ms status=200 bytes=224
2016-04-23T00:59:33.426223+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/ispassword" host=lit-island-38801.herokuapp.com request_id=e861aa6f-c40b-440c-af1c-3a24eded9c2c fwd="152.3.43.156" dyno=web.1 connect=1ms service=30001ms status=503 bytes=0
我的Android应用程序请求代码就像这样
RequestQueue queue = Volley.newRequestQueue(Login.this);
StringRequest strRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>()
{
@Override
public void onResponse(String response)
{
Log.d(TAG,response);
if(response.equals("no")){
onLoginFailed();
Toast.makeText(getBaseContext(), "Login failed", Toast.LENGTH_LONG).show(); //show the toast for a long time
Intent intent = new Intent(Login.this, Login.class);
startActivity(intent);
finish();
}
//Toast.makeText(getApplicationContext(), response, Toast.LENGTH_SHORT).show();
String del =":";
String []res = response.split(del);
fetched_pw = res[1].replaceAll("\\}","").replaceAll("\"","").replaceAll("\\]","");
Log.i(TAG,fetched_pw);
Log.i(TAG,password);
Log.i(TAG,"version1");
if(password.equals(fetched_pw)){
progressDialog.show();
onLoginSuccess();
progressDialog.dismiss();
}
else{
onLoginFailed();
progressDialog.dismiss();
}
}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error)
{
Toast.makeText(getApplicationContext(), error.toString(), Toast.LENGTH_SHORT).show();
}
})
{
@Override
protected Map<String, String> getParams()
{
Map<String, String> params = new HashMap<String, String>();
params.put("email", email);
return params;
}
};
queue.add(strRequest);
}
我的node.js代码来处理这个就像
app.post('/ispassword', function (req, res) {
var pg = require('pg');
var ans;
pg.defaults.ssl = true;
pg.connect("postgres://abcdefghij:ev0Y_GVqmX5zd22oM3KQ8smXS5@ec2-11-11-11-111-1-1.compute-1.amazonaws.com:5432/d4drnop61h6hv7", function(err, client) {
if (err) throw err;
console.log('Get to Function ispassword');
var email = req.param('email');
client.query("select password from USER_TABLE where email = $1;",[email],function (error,results) {
if(results.rowCount>0){
var que = client.query("select password from USER_TABLE where email = $1;",[email]);
//var que = client.query("select password from USER_TABLE");
que.on("row", function (row, result) {
//console.log(row);
result.addRow(row);
});
que.on("end", function (result) {
res.send(result.rows);
});
console.log("send");
}
else{
res.send('no');
}
});
});
});
有人可以保存我的一天吗?