在Android Studio中,我尝试通过HTTP get request
向PHP脚本发送Volley
。我检查了PHP链接,它是有效的。但由于某种原因,我不断收到错误的响应。而不是获取PHP脚本响应。有什么想法吗?
public class FourActivity extends AppCompatActivity {
private Button bn;
private TextView txt;
private String server_url = "http://192.168.0.152/server.php";
public FourActivity() {
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_four);
bn = (Button) findViewById(R.id.bn);
txt = (TextView) findViewById(R.id.txt);
bn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final RequestQueue requestQueue = Volley.newRequestQueue(FourActivity.this);
StringRequest stringRequest = new StringRequest(Request.Method.POST, server_url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
txt.setText(response);
requestQueue.stop();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
txt.setText("error");
error.printStackTrace();
requestQueue.stop();
}
}
);
requestQueue.add(stringRequest);
}
});
}
}
错误日志
答案 0 :(得分:1)
您需要在应用清单上添加<uses-permission android:name="android.permission.INTERNET" />
权限。
希望这有帮助。