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

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

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

第一次錯誤:

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

file 沒有傳值,或者非預定格式,stream resource

第二次錯誤:

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

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

php 調用參考:

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

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

Psr\Http\Message\StreamInterface 的實例。

$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ù)組,同樣需要重組,不重組就是第三個問題:
Invalid resource type: array

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

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

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論