拼写检查API在PHP中返回404错误 [英] Spell Check API returns 404 error in PHP

查看:161
本文介绍了拼写检查API在PHP中返回404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好。


我正在尝试实现一个非常简单的拼写检查基于PHP的程序,但即使下面的示例也给出了以下错误:


{" statusCode":404," message":" Resource not found"这是代码:

<?php 
//此示例使用来自HTTP Components的Apache HTTP客户端(http://hc.apache.org/httpcomponents-client-ga/)
require_once'HTTP / Request2.php';

$ request = new Http_Request2('http://bingapis.azure-api.net/api/v5/spellcheck');
$ url = $ request-> getUrl();

$ headers = array(
//请求标头
'Content-Type'=>'application / x-www-form-urlencoded',
' Ocp-Apim-Subscription-Key'=>'[my key]',
);

$ request-> setHeader($ headers);

$ parameters = array(
//请求参数
'mode'=>'spell',
);

$ url-> setQueryVariables($ parameters);

$ request-> setMethod(HTTP_Request2 :: METHOD_POST);

//请求正文
$ request-> setBody(" Helllo World");

尝试
{
$ response = $ request-> send();
echo $ response-> getBody();
}
catch(HttpException $ ex)
{
echo $ ex;
}

?>


任意想法?



解决方案

你能来吗?试试https?


另外,你想要使主体'text = Hello + World',这意味着你需要'text ='前缀,并进行必要的URL编码(即在你的情况下,将空格转换为'+'字符。)


Hello here.

I am trying to implement a very simple spell check PHP based program, but even the sample below gives me the following error:

{ "statusCode": 404, "message": "Resource not found" }

Here is the code:

<?php
// This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
require_once 'HTTP/Request2.php';

$request = new Http_Request2('http://bingapis.azure-api.net/api/v5/spellcheck');
$url = $request->getUrl();

$headers = array(
    // Request headers
    'Content-Type' => 'application/x-www-form-urlencoded',
    'Ocp-Apim-Subscription-Key' => '[my key]',
);

$request->setHeader($headers);

$parameters = array(
    // Request parameters
    'mode' => 'spell',
);

$url->setQueryVariables($parameters);

$request->setMethod(HTTP_Request2::METHOD_POST);

// Request body
$request->setBody("Helllo World");

try
{
    $response = $request->send();
    echo $response->getBody();
}
catch (HttpException $ex)
{
    echo $ex;
}

?>

Any ideas?

解决方案

Can you try https instead?

Also, you want make the body 'text=Hello+World', meaning you'll need the 'text=' prefix, and do the requisite URL encoding (i.e. in your case converting the space to a '+' char.)


这篇关于拼写检查API在PHP中返回404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆