【发布时间】:2017-10-29 00:39:06
【问题描述】:
我已经编写了一个 Android 代码并与网络服务器 (phpMyAdmin) 连接。现在问题来了,我只能从一个网络(即我自己的互联网)访问服务器,每当我尝试从其他网络访问它时,都会出现 volley.timeout 错误。
有些人建议我公开您的服务器地址,有些人建议我购买服务器。我对这些东西不太了解,因为我是 Android 新手,我想从每个网络访问我的数据库。
这是我的代码:
public class MainActivity extends AppCompatActivity {
Button Show;
TextView Result;
RequestQueue requestQueue;
String URL="http://192.168.0.103/fetchdata.php";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Show=(Button) findViewById(R.id.Show);
Result=(TextView) findViewById(R.id.textView);
requestQueue= Volley.newRequestQueue(getApplicationContext());
Show.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
JsonObjectRequest jsonobjectrequest=new JsonObjectRequest(Request.Method.POST,URL,
new Response.Listener<JSONObject>()
{
@Override
public void onResponse(JSONObject response) {
try{
JSONArray signin=response.getJSONArray("signin");
for (int i=0;i<signin.length();i++)
{
JSONObject signin1=signin.getJSONObject(i);
String Username=signin1.getString("username");
String Password=signin1.getString("password");
String Email=signin1.getString("email");
Result.append(Username+" "+Email+" "+Password+ "\n");
}
Result.append("===\n");
}catch(JSONException e){
e.printStackTrace();
}
}
}, new Response.ErrorListener(){
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, error.toString(), Toast.LENGTH_SHORT).show();
}
});
requestQueue.add(jsonobjectrequest);
}
});
}
}
【问题讨论】:
标签: android phpmyadmin