PHP API - webLM的curl请求 [英] PHP API - curl request for webLM

查看:72
本文介绍了PHP API - webLM的curl请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在将我的代码转换为牛津项目,我一直看到错误:

I'm converting my code to Oxford project and I keep on seeing the error:

{" ; error":{" code":" BadArgument"," message":" Argument \" model \"未指定。"}}

{"error":{"code":"BadArgument","message":"Argument \"model\" is not specified."}}

我正在使用带有以下curl请求的PHP API。这些参数在API测试控制台中起作用:

I'm using the PHP API with the following curl request. Those parameters work in the API test console:

<?php



$ url ='https:// api。 projectoxford.ai/text/weblm/v1.0/breakIntoWords';
$


$ headers = array(

  '内容-Type:application / json',

  'Ocp-Apim-Subscription-Key:xxx'          < br $> b $ b);

$


$ parameters = array(

                  'text'=>'iwanttobreakfree',

       'model'=>'body',

                'order'=>'1',

                'maxNumOfCandidatesReturned'=>'5'

);



$ parameters = http_build_query($ parameters);
$


$ request = curl_init();

curl_setopt($ request,CURLOPT_RETURNTRANSFER,true);

curl_setopt($ request,CURLOPT_URL,$ url);
$
curl_setopt($ request,CURLOPT_POST,true);

curl_setopt($ request,CURLOPT_POSTFIELDS,$参数);
$
curl_setopt($ request,CURLOPT_HTTPHEADER,$ headers);
$


$ resp = curl_exec($ request);



echo $ resp;



curl_close($ request);



?>

<?php

$url= 'https://api.projectoxford.ai/text/weblm/v1.0/breakIntoWords';

$headers = array(
   'Content-Type: application/json',
   'Ocp-Apim-Subscription-Key: xxx'          
);


$parameters = array(
                   'text' => 'iwanttobreakfree',
        'model' => 'body',
                'order' => '1',
                'maxNumOfCandidatesReturned' => '5'
);

$parameters = http_build_query($parameters);

$request = curl_init();
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_URL, $url);
curl_setopt($request, CURLOPT_POST, true);
curl_setopt($request, CURLOPT_POSTFIELDS, $parameters);
curl_setopt($request, CURLOPT_HTTPHEADER, $headers);

$resp = curl_exec($request);

echo $resp;

curl_close($request);

?>

我使用了错误的参数吗?

Am I using wrong parameters ?

感谢您的支持支持,

最好的问候,

Francois

Best Regards,
Francois

推荐答案

这个API,参数以查询参数的形式发送,但你已经将它们设置为POST字段。

For this API, the arguments are sent in the form of query parameters, but you've set them to POST fields.

我不是PHP专家,但它看起来像你想要的将

I'm not a PHP expert, but it looks like what you want is to sent


参数发送到
http_build_query 方法。


这篇关于PHP API - webLM的curl请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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