【发布时间】:2016-07-22 15:10:30
【问题描述】:
我构建了一个小型 laravel 应用程序,它只有一个表单并将数据保存到数据库(phpmyadmin)。现在我尝试在我的 android 应用程序中显示该数据,我尝试通过 ip 获取它。
主要活动如下所示:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onConnect(View view) {
new Thread(){
public void run(){
HttpClient myClient = new DefaultHttpClient();
HttpPost post = new HttpPost("http://192.168.145.33:8000/gaIndex");
try {
List<NameValuePair> myArgs = new ArrayList<NameValuePair>();
myArgs.add(new BasicNameValuePair("email", "test@hotmail.de"));
myArgs.add(new BasicNameValuePair("password", "test"));
post.setEntity(new UrlEncodedFormEntity(myArgs));
HttpResponse myResponse = myClient.execute(post);
BufferedReader br = new BufferedReader( new InputStreamReader(myResponse.getEntity().getContent()));
String line = "";
while ((line = br.readLine()) != null)
{
Log.d("mytag", line);
}
}
catch (IOException e) {
e.printStackTrace();
}
}
}.start();
}
}
如果我启动应用程序并按下按钮连接控制台给我一堆 html...
我也在控制台输出中得到了这个:
令牌不匹配异常 在 VerifyCsrfToken.php 第 53 行:
有谁知道我做错了什么。
【问题讨论】:
-
您使用的是 L 5.1 还是 5.2?
-
您应该在这里使用 RESTful 路由模式,而不是直接尝试通过 Android 应用访问视图。
标签: php android database api laravel