我在laravel 5.1中创建了几个表单,现在我在使用IFrame的另一个站点上使用这些表单.这些表单适用于除Safari之外的所有浏览器.当我在填写表单后尝试提交/发布数据时,我收到错误"CSRF Token Mismatch",我不知道这里有什么问题,csrf令牌也正在创建和发送.这只发生在safari浏览器的情况下.
有人可以指导我,我怎么能摆脱这个问题?
重现步骤:
创建一个表单,然后通过IFrame使用它.提交表单后,将生成CSRF令牌不匹配错误.
怎么解决这个?请帮忙!
代码示例:
<form method="post" action="/step1/{{$voucher->user_id}}" accept-charset="UTF-8">
<input name="_method" type="hidden" value="post">
{!! csrf_field() !!}
<div class="row" style="margin-top:15px; margin-bottom:15px;">
<div class="col-md-4 col-xs-5 hidden">
<input name="voucher_id" type="hidden" value="{{$voucher->id}}" id="voucher_id">
<input class="form-control spin text-center qty1" name="qty" id="qty" type="text" value="1" >
<input name="r_full_name" type="hidden" value="" id="r_full_name">
</div>
<div class="col-md-3 col-xs-3">
<button type="submit" class="btn btn-theme"><i class="fa fa-shopping-cart" aria-hidden="true"></i> | BUY</button>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
这是示例代码... AGAIN所有这些在任何其他浏览器(FF,Chrome)中都很完美,但是当我将此表单放入另一个站点的iframe时,我得到了TokenMissmatch错误...
我使用Dingo和Laravel 5.1来创建简单的API.
所以在route.php我有:
$api = app('Dingo\Api\Routing\Router');
$api->version('v1', function($api) {
$api->get('getvoucher', 'App\Http\Controllers\BitemsController@index');
$api->get('update/{key}', 'App\Http\Controllers\BitemsController@update');
$api->post('store', 'App\Http\Controllers\BitemsController@store');
$api->post('authenticate', 'App\Http\Controllers\AuthenticateController@authenticate');
$api->post('logout', 'App\Http\Controllers\AuthenticateController@logout');
$api->get('token', 'App\Http\Controllers\AuthenticateController@getToken');
});
Run Code Online (Sandbox Code Playgroud)
我的BitemsController是:
public function index(Request $request)
{
$bitem = Bitem::where('key',$request->key)->where('id',$request->pin)->first();
return $bitem;
}
public function store(Request $request)
{
$bitem = new Bitem($request->all());
$bitem->save;
return $bitem;
}
Run Code Online (Sandbox Code Playgroud)
现在我使用POSTMAN应用程序来测试API,当我将GET发送到localhost时:8888/api/getvoucher一切都很好,但是当我发出POST请求来存储一些数据时,我得到了错误:
"message": "500 Internal Server Error",
"status_code": 500,
"debug": {
"line": 53,
"file": "C:\\wamp\\www\\dine\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken.php",
"class": "Illuminate\\Session\\TokenMismatchException",
"trace": [
Run Code Online (Sandbox Code Playgroud)
要解决此问题,我尝试添加:
protected $except = [
'api/*',
];
Run Code Online (Sandbox Code Playgroud)
在中间件VerifyCsrfToken.php中,但是工作.
请告诉我如何解决我的问题......
我需要集成一个API,所以我要编写函数:
public function test() {
$client = new GuzzleHttp\Client();
try {
$res = $client->post('http://example.co.uk/auth/token', [
'headers' => [
'Content-Type' => 'application/x-www-form-urlencoded',
],
'json' => [
'cliend_id' => 'SOMEID',
'client_secret' => '9999jjjj67Y0LBLq8CbftgfdreehYEI=',
'grant_type' => 'client_credentials'
]
]);
$res = json_decode($res->getBody()->getContents(), true);
dd($res);
}
catch (GuzzleHttp\Exception\ClientException $e) {
$response = $e->getResponse();
$result = json_decode($response->getBody()->getContents());
return response()->json(['data' => $result]);
}
}
Run Code Online (Sandbox Code Playgroud)
作为回应,我收到消息:
{"data":{"error":"invalid_clientId","error_description":"ClientId should be sent."}}
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试在POSTMAN应用程序中使用相同的数据运行相同的URL时,我得到了正确的结果:
我的代码有什么不好?我form_params
也发送正确的尝试将form_params更改为json,但再次出现相同的错误...
如何解决我的问题?
我在控制器中使用 Laravel Dusk,以便用户使用我的网站获取任何网站的屏幕截图。
我的代码:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Laravel\Dusk\ElementResolver;
use Exception;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Laravel\Dusk\Browser;
use Laravel\Dusk\Chrome\ChromeProcess;
use Facebook\WebDriver\WebDriverBy;
use Mail;
class ScreenController extends Controller {
public function take_screenshoot() {
$process = (new ChromeProcess)->toProcess();
if ($process->isStarted()) {
$process->stop();
}
$process->start();
$options = (new ChromeOptions)->addArguments([
'--disable-gpu',
'--headless',
'--window-size=1920,1080',
'--no-sandbox'
]);
$capabilities = DesiredCapabilities::chrome()->setCapability(ChromeOptions::CAPABILITY, $options);
$driver = retry(5, function () use ($capabilities) {
return RemoteWebDriver::create('http://localhost:9515', $capabilities, 50000, 60000);
}, 50);
$browser = new Browser($driver, …
Run Code Online (Sandbox Code Playgroud) 我需要使用来自 API 的数据。
我创建了一个函数:
public function getItems()
{
$client = new \GuzzleHttp\Client();
$res = $client->get('https://app.example.com/api/getItems');
$vouchers = json_decode($res->getBody(), true);
dd($vouchers);
return view('api', compact('vouchers'));
}
Run Code Online (Sandbox Code Playgroud)
并dd($vouchers)
回复我:
现在,当我尝试将 $vouchers 数组与刀片引擎一起使用时,例如:
<body>
@foreach ($vouchers as $v)
<p>{{$v->name}}</p>
@endforeach
</body>
Run Code Online (Sandbox Code Playgroud)
我有错误:
"Trying to get property 'name' of non-object (View: .... etc...
Run Code Online (Sandbox Code Playgroud)
我如何将数组转换为雄辩的集合。我用的是最新的 Laravel 5.7 版本
我使用Laravel HTML创建表单,但遇到了问题,因此在创建表单时有:
{!! Form::open(['url'=>'vocuhers','files' => 'true','enctype'=>'multipart/form-data']) !!}
@include('vouchers.form',['submitButtonText'=>'Click to Add New Vocuher'])
{!! Form::close() !!}
Run Code Online (Sandbox Code Playgroud)
但是,当我在浏览器中看到HTML表单时,只有:
<form method="POST" action="http://localhost:8888/vouchers" accept-charset="UTF-8">
<input name="_token" type="hidden" value="dfgdfgdfgdfgdf">
Run Code Online (Sandbox Code Playgroud)
所以在哪里
enctype="multipart/form-data"
Run Code Online (Sandbox Code Playgroud)
哪个可以让我从表单上传文件?
为什么我没有得到这个HTML输出:
<form method="POST" action="https://bedbids.com/chats" accept-charset="UTF-8" enctype="multipart/form-data">
<input name="_token" type="hidden" value="dsfdfgdfgdfgdfg">
Run Code Online (Sandbox Code Playgroud)
这到底是什么问题?
将日期名称转换为日期位置的最佳方法是什么。
我有数组:
var days = ['Monday','Sunday','Friday']
Run Code Online (Sandbox Code Playgroud)
如何转换为: newArray = [0,6,4]
我试试这个:
function getClosedDates() {
var url = "/getClosedDates"; // the script where you handle the form input.
var WEEKDAYS = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
var newArray = [];
var days = [];
$.ajax({
type: "GET",
url: url,
dataType: "json",
success: function(data)
{
days = data.data.ClosedDays;
newArray = days.map(function(day) {
return WEEKDAYS.indexOf(day);
});
}
});
return newArray;
};
Run Code Online (Sandbox Code Playgroud)
但我得到 [],空数组...为什么?
我创建了一个API,现在我尝试访问该API.邮差一切都很完美,工作正常:
但当我尝试使用guzzle/laravel代码时:
$res3 = $client3->post('https://app.EXAMPLE.com/api/update/'.$serial, [
'headers' => [
'Authorization' => 'Bearer '.$res2['token'],
'Content-Type' => 'application/json'
],
'form_params' => [
'token' => $res2['token'],
'bookingdate' => '07/07/2018 12:00 am',
'notes' => $SpecialRequests
]
]);
Run Code Online (Sandbox Code Playgroud)
我有:
宾语
data:debug:class:"Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException"file:"/ home/user_name/public_html/vendor/dingo/api/src/Auth/Auth.php"line:113
有什么问题?什么在Postman工作,但不适用于Laravel/Guzzle图书馆?
我用代码创建了一个包含集合的数组:
$hours = Voucher::where('created_at','>=', Carbon::now()->startOfMonth())->get()->groupBy(function($item)
{
return $item->created_at->format('H');
});
dd($hours);
Run Code Online (Sandbox Code Playgroud)
所以我得到这样的数据:
SO 键是小时 (00-23)。
我如何安排它从 00、01、02、03 开始......
我需要连接到 API,所以我编写了一个函数:
try {
$res4 = $client3->post('https://api.example.co.uk/Book', [
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ajhsdbjhasdbasdbasd',
],
'json' => [
'custFirstName' => $FirstName,
'custLastName' => $Surname,
'custPhone' => $Mobile,
'custEmail' => $Email,
]
]);
} catch (GuzzleHttp\Exception\ClientException $e) {
$response = $e->getResponse();
$result = json_decode($response->getBody()->getContents());
$item->update(['status' => 'Problems at step3']);
Mail::raw('Problem at STEP 3', function ($message) use ($serial) {
$message->from('asd.asd@gmail.com', 'asd.asd@gmail.com');
$message->subject('We got a problem etc.');
$message->to('john.smith@gmail.com');
});
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我需要调用 API,但在 API 关闭的情况下,我会编写 catch 函数。 …
我正在使用 Laravel Dusk 并且我在一个页面上有这个 HTML:
<div>
<textarea class="" data-auto="notes" style="height: 72px;"></textarea>
<button class="">
<svg viewBox="0 0 9.877141 7.3747067" height="7.375" width="9.877">
<path d="M8.517 0a.56.56 0 0 0-.397.166L3.896 4.418l-2.14-2.14a.56.56 0 0 0-.796 0l-.795.794a.56.56 0 0 0 0 .795l2.53 2.53c.005.005.006.012.011.017l.795.795.002.002c.22.219.576.218.795-.002l5.416-5.455A.561.561 0 0 0 9.712.96L8.917.164h-.002A.561.561 0 0 0 8.517 0z" ></path>
</svg>
</button>
<div class=""></div>
</div>
Run Code Online (Sandbox Code Playgroud)
如何在文本区域中输入文本并单击按钮?没有名字,没有类,没有ID……只有属性……
我尝试:
$browser->element("textarea[data-auto='notes']")->type('some notes');
$browser->element("/button/svg")->click();
$browser->pause(1000);
Run Code Online (Sandbox Code Playgroud)
但什么也没发生。
selenium laravel selenium-chromedriver selenium-webdriver laravel-dusk
从 API 文档我有这个curl
请求:
curl https://api.example.com/api/Jwt/Token ^
-d Username="asd%40gmail.com" ^
-d Password="abcd1234"
Run Code Online (Sandbox Code Playgroud)
现在我正在尝试使用 Guzzle 库在 Laravel 5.1 中创建该请求,所以我写道:
public function test()
{
$client = new GuzzleHttp\Client();
$res = $client->createRequest('POST','https://api.example.com/api/Jwt/Token', [
'form_params' => [
'Username' => 'asd%40gmail.com',
'Password' => 'abcd1234'
]
]);
$res = json_decode($res->getBody()->getContents(), true);
dd ($res);
}
Run Code Online (Sandbox Code Playgroud)
但我收到此错误:
***ErrorException in Client.php line 126:
Argument 3 passed to GuzzleHttp\Client::request() must be of the type array, string given, called in /home/ibook/public_html/vendor/guzzlehttp/guzzle/src/Client.php on line 87 and defined***
Run Code Online (Sandbox Code Playgroud)
问题是什么,我该如何解决该错误?
ps我也试过
$res = …
Run Code Online (Sandbox Code Playgroud) laravel ×12
php ×7
guzzle ×4
arrays ×3
collections ×2
dingo-api ×2
eloquent ×2
guzzle6 ×2
guzzlehttp ×2
javascript ×2
laravel-5.1 ×2
laravel-dusk ×2
postman ×2
api ×1
csrf ×1
forms ×1
html ×1
iframe ×1
max ×1
middleware ×1
safari ×1
selenium ×1
sorting ×1
sum ×1
webdriver ×1