欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

記Laravel調(diào)用Gin接口調(diào)用formData上傳文件的實(shí)現(xiàn)方法

 更新時(shí)間:2019年12月12日 08:28:53   作者:King_Chin  
這篇文章主要介紹了記Laravel調(diào)用Gin接口調(diào)用formData上傳文件的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

第一次錯(cuò)誤:

[output] 【c.FormFile error==>】 multipart: NextPart: EOF

file 沒有傳值,或者非預(yù)定格式,stream resource

第二次錯(cuò)誤:

[output] 【c.FormFile error==>】 multipart: NextPart: bufio: buffer full

header頭不需要 content-type => 'multipart/form-data'

php 調(diào)用參考:

你可以通過使用 multipart 請求參數(shù)來發(fā)送表單 (表單 enctype 屬性需要設(shè)置 multipart/form-data ) 文件, 該參數(shù)接收一個(gè)包含多個(gè)關(guān)聯(lián)數(shù)組的數(shù)組,每個(gè)關(guān)聯(lián)數(shù)組包含一下鍵名:

  • name: (必須,字符串) 映射到表單字段的名稱。
  • contents: (必須,混合) 提供一個(gè)字符串,可以是 fopen 返回的資源、或者一個(gè)

Psr\Http\Message\StreamInterface 的實(shí)例。

$response = $client->request('POST', 'http://post', [
  'multipart' => [
    [
      'name'   => 'field_name',
      'contents' => 'abc'
    ],
    [
      'name'   => 'file_name',
      'contents' => fopen('/path/to/file', 'r')
    ],
    [
      'name'   => 'other_file',
      'contents' => 'hello',
      'filename' => 'filename.txt',
      'headers' => [
        'X-Foo' => 'this is an extra header to include'
      ]
    ]
  ]
]);

ps:
multipart 格式如上,需要注意的是參數(shù)如果是數(shù)組,同樣需要重組,不重組就是第三個(gè)問題:
Invalid resource type: array

修改參數(shù)格式為 json, 畢竟跨語言 json xml 才是王道

```
$response = $client->request('POST', 'http://post', [
    'multipart' => [
      [
        'name'   => 'field_name',
        'contents' => json_encode(["abc", "abd"])
      ]
    ]
  ]
]);

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論