Php 请求中的pdf laravel

Php 请求中的pdf laravel,php,laravel,api,post,Php,Laravel,Api,Post,因此,对于一个应用程序,我必须将一个pdf发送到一个api中,然后对该pdf执行一些操作,然后将其发送到另一个api,然后返回结果 问题n1: 我不知道如何获取与邮递员一起发送的pdf 我试过了 这似乎不起作用,因为我无法获取名为 test.pdf 并且有一个 Test Dit is een test 所以在这段时间里,我是这样做的 $parser = new Parser(); $pdf = $parser->parseFile('pdf/test.pdf'); $text = p

因此,对于一个应用程序,我必须将一个pdf发送到一个api中,然后对该pdf执行一些操作,然后将其发送到另一个api,然后返回结果

问题n1:

我不知道如何获取与邮递员一起发送的pdf 我试过了

这似乎不起作用,因为我无法获取名为

test.pdf 
并且有一个

Test
Dit is een test
所以在这段时间里,我是这样做的

$parser = new Parser();
$pdf = $parser->parseFile('pdf/test.pdf');
$text = pdf->getText();
问题n2:

我将转换后的pdf发送给的api声明requestbody无效 我用Guzzle来表示请求

    $headers =
        [
            'headers' => [
                'Ocp-Apim-Subscription-Key' => 'xxxxxxxxxxxxxxxxxxxxxxx',
                'Accept' => 'application/json',
                'Content-Type' => 'application/json']
        ];
    $body =
        '{
            "documents": [
            {
            "language": "nl",
            "id": "1",
            "text":"' . $text . '"}
            ]
        }';

    $client = new Client();

    $response = $client->request('POST', 'https://westeurope.api.cognitive.microsoft.com/text/analytics/v2.0/KeyPhrases', $headers, $body);
它给

`Client error: `POST

导致了一个
400错误的请求
响应:\n
{“代码”:“BadRequest”,“消息”:“无效请求”,“内部错误”:
{“代码”:“InvalidRequestBodyFormat”,“消息”:“请求正文”
(截断…)\n
//似乎无法正确格式化此文件

有人能帮我吗?
并解释我做错了什么如果他们有时间回答你问题的第一部分(n1),你可以通过以下方式获得上传的文件:

$file = $request->file('test'); // where 'test' is the 'name' of this file input
更多信息请点击此处:

对于第二部分(n2),看起来您正在传递一个无效的实体。请尝试以下操作:

$body = [
    'documents' => [
        [
            'language' => 'nl',
            'id' => '1',
            'text' => $text,
        ],
    ]
];
$headers = [
    'Ocp-Apim-Subscription-Key' => 'xxxxxxxxxxxxxxxxxxxxxxx',
    'Accept' => 'application/json',
    'Content-Type' => 'application/json' // this might not be needed since Guzzle should add this automatically
];
$client->request('POST','https://westeurope.api.cognitive.microsoft.com/text/analytics/v2.0/KeyPhrases', [
    'json' => $body,
    'headers' => $headers,
    'debug' => true, // to get more info on the error ...
]);

我试过了,但现在它说订阅密钥不正确,但如果我直接与邮递员联系就可以了,这很容易混淆。您可以尝试启用
debug
选项,看看这是否为您提供了更多信息。请参阅我的更新答案。k nvm必须将其合并为一个大请求thx以获得解决方案
$body = [
    'documents' => [
        [
            'language' => 'nl',
            'id' => '1',
            'text' => $text,
        ],
    ]
];
$headers = [
    'Ocp-Apim-Subscription-Key' => 'xxxxxxxxxxxxxxxxxxxxxxx',
    'Accept' => 'application/json',
    'Content-Type' => 'application/json' // this might not be needed since Guzzle should add this automatically
];
$client->request('POST','https://westeurope.api.cognitive.microsoft.com/text/analytics/v2.0/KeyPhrases', [
    'json' => $body,
    'headers' => $headers,
    'debug' => true, // to get more info on the error ...
]);