0

我在向外部 API (Laravel) 发送数据时遇到错误。我不明白问题是什么。一切似乎都是正确的。但是,不幸的是,我在网络上的其他网站上没有找到正确的答案。

这是我的发送方法

public function checkFile(Request $request)
{
    $response = Http::withHeaders([
        'Content-Type' => 'multipart/form-data'
    ])
        ->attach('CodeFile', $request->file('CodeFile'))
        ->withBasicAuth($this->login, $this->password)
        ->post($this->base_url.'/api/Checker/CheckFile', [
            'CodeFile' => $request->file('CodeFile'),
            'LanguageType' => $request->LanguageType,
            'ProblemShortCode' => $request->ProblemShortCode
        ]);

    return $response;
}

输出

{
  "title": "One or more validation errors occurred.",
  "status": 400,
  "traceId": "00-ab5d61bff21331449b27984d982a0e21-78eba0448be1c342-00",
  "errors": {
    "": [
      "Failed to read the request form. Missing content-type boundary."
    ]
  }
}
4

1 回答 1

0

尝试删除

'Content-Type' => 'multipart/form-data'

标题。

有时由上传者自动设置。

让我知道

于 2022-02-27T17:53:38.093 回答