Laravel $request->all() 使用 multipart/form-data 是空的
我正在发送请求,包括表单数据对象,其中包含从角度4到laravel api的一些数据...有时正确接收请求数据,有时请求为空“空请求”
这是我的请求详细信息
Accept:application/json
Accept-Encoding:gzip, deflate, br
Accept-Language:en-US,en;q=0.9
Authorization:Bearer ---------
Connection:keep-alive
Content-Length:973
Content-Type:multipart/form-data; boundary=----WebKitFormBoundarydEkuATdI8JBFdnBM
Host:127.0.0.1:8000
Origin:http://localhost:4200
Referer:http://localhost:4200/shop_admin
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36
请求负载
------WebKitFormBoundarydEkuATdI8JBFdnBM
Content-Disposition: form-data; name="business_id"
249
------WebKitFormBoundarydEkuATdI8JBFdnBM
Content-Disposition: form-data; name="maintenance_flag"
0
------WebKitFormBoundarydEkuATdI8JBFdnBM
Content-Disposition: form-data; name="type"
shop
------WebKitFormBoundarydEkuATdI8JBFdnBM
Content-Disposition: form-data; name="name"
qewqweqweqwe
------WebKitFormBoundarydEkuATdI8JBFdnBM
Content-Disposition: form-data; name="website_uri"
------WebKitFormBoundarydEkuATdI8JBFdnBM
Content-Disposition: form-data; name="phone_number"
------WebKitFormBoundarydEkuATdI8JBFdnBM
Content-Disposition: form-data; name="facebook_link"
------WebKitFormBoundarydEkuATdI8JBFdnBM
Content-Disposition: form-data; name="logo_uri"
uploads/businesses/249/249_1.jpg
------WebKitFormBoundarydEkuATdI8JBFdnBM
Content-Disposition: form-data; name="brands"
undefined
------WebKitFormBoundarydEkuATdI8JBFdnBM--
更新
这是我的代码
角度侧:
表单数据对象这里是角表单数据对象
let formData: FormData = new FormData();
formData.append( 'business_id', that.businessId );
formData.append( 'maintenance_flag', that.maintenance_flag );
formData.append( 'type', edit_type );
formData.append( 'name', name );
formData.append( 'website_uri', website );
formData.append( 'phone_number', phone );
formData.append( 'facebook_link', face );
formData.append( 'logo_uri', that.basicData.logo_uri );
formData.append( 'brands', that.selectedBrands );
if ( pic.files.length > 0 )
formData.append( 'logo_uri', pic.files[ 0 ] );
应用程序接口:
that.apiService.changeBusiness( formData ).subscribe( ( res ) =>
{
console.log( res );
}
shopUpdate ( shop_basic_info ){
return this.http.post( environment.api_base_url + 'api/shop_update', shop_basic_info ).map( res => res.json() );
}
拉拉维尔侧
路线
Route::post('/shop_update', 'ShopController@handleUpdate');
控制器文件
public function handleUpdate(Request $request)
{
return $request->all();
}