Javascript PHP忽略初始值202

Javascript PHP忽略初始值202,javascript,php,ajax,guzzle,Javascript,Php,Ajax,Guzzle,我正在编写一个PHP API客户端,API是用ASP.net(C#)编写的 我可以使用此Javascript函数正确访问数据: $.ajax({ type: "POST", url: "https://www.eastmidlandstrains.co.uk/services/LiveTrainInfoService.svc/GetLiveBoardJson", data: JSON.stringify({ request: {

我正在编写一个PHP API客户端,API是用ASP.net(C#)编写的

我可以使用此Javascript函数正确访问数据:

    $.ajax({
    type: "POST",
    url: "https://www.eastmidlandstrains.co.uk/services/LiveTrainInfoService.svc/GetLiveBoardJson",
    data: JSON.stringify({
        request: {
            OriginText: "Derby",
            DestText: "Nottingham",
            Departures: true
        }
    }),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    processdata: true,
    success: function (result) {
        console.log(JSON.parse(result.d));
    },
    error: function (jqXHR, textStatus, errorThrown) {
        console.log('Error: ', errorThrown);
    }
});
我正在尝试使用Guzzle在PHP中复制这个请求。到目前为止,我已经做到了这一点:

class EMTClient
{
    const EMT_API_URL = "https://www.eastmidlandstrains.co.uk/services/LiveTrainInfoService.svc/GetLiveBoardJson";

    /**
     * @param string $startLocation
     * @param string $endLocation
     * @return mixed
     */
    public function getJourneys(string $startLocation, string $endLocation)
    {
        $client = new GuzzleHttp\Client();

        $request = new GuzzleHttp\Psr7\Request('POST', self::EMT_API_URL, [
            'json' => json_encode([
                'request' => [
                    'OriginText' => $startLocation,
                    'DestText' => $endLocation,
                    'Departures' => true
                ]
            ]),
            'allow_redirects' => false
        ]);
        $promise = $client->sendAsync($request)->then(function ($response) {
            var_dump($response->getBody());
            return $response;
        });
        $promise->wait();

        return $promise->getBody();
    }
}
唯一的问题是,这个API在处理响应并返回数据之前返回一个初始的202接受响应,PHP版本正在捕获这个202并返回一个空响应


这个JS函数工作得很好,但我需要PHP版本,我还使用composer,这样我就可以包含任何PHP库。

在我看来,一个版本将设置与另一个版本略有不同的标题

您应该检查服务器期望的标题,然后查看PHP和JS生成的标题,并且应该确保这些匹配

这是两个相同请求失败的最明显原因。

“此API在处理响应和返回数据之前返回初始的202接受响应”-您能否澄清这到底意味着什么?一个请求不能用一个以上的状态代码来回答,那么API到底做什么呢?