我构建了一个小型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 ...
我在控制台输出中也得到了这个:
TokenMismatchException 在VerifyCsrfToken.php中 第53行:
有人知道我做错了吗。
答案 0 :(得分:2)
Laravel有一个verifyCsrf中间件应用于所有传入请求,以保护应用程序不受Cross Site Request Forgery
的影响您可以通过将路由添加到VerifyCsrfToken类中的$except
数组来绕过此路径:
在app / Http / Middleware / VerifyCsrfToken.php
中<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
class VerifyCsrfToken extends BaseVerifier
{
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
'gaIndex'
];
}