Azure ML使用Web服务PHP Curl [英] Azure ML consume Web Service PHP Curl
问题描述
我无法使用php curl消费网页。
I can not consume the web using php curl.
错误:400 - "未提供请求正文或反序列化请求正文时出错。"
ERROR: 400 - "No request body provided or error in deserializing the request body."
代码:
<?php
$ data = array (
'输入' => array (
'Input1' => array ( array (
'Frequencia' => " 30" ,
'Vazao' => " 1" ,
'Resultado' => "" ,
) ,
) ,
) ,
'GlobalParameters' => new StdClass ( ) ,
) ;
$ data_string = json_encode ( $ data < span style ="color:blue; font-family:monospace; font-size:13.3333px; white-space:nowrap">) ;
echo $ data_string ;
$ curl = curl_init ( ) ;
curl_setopt_array ( $ curl < span style ="color:blue; font-family:monospace; font-size:13.3333px; white-space:nowrap">, array (
CURLOPT_URL => " https:// ussout hcentral.services.azureml.net/XXXXXXXXXX",
CURLOPT_RETURNTRANSFER => true ,
CURLOPT_SSL_VERIFYPEER => false ,
// CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_ENCODING => "" ,
CURLOPT_MAXREDIRS => 10 ,
CURLOPT_TIMEOUT => 30 ,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1 ,
CURLOPT_CUSTOMREQUEST => " POST" ,
CURLOPT_POSTFIELDS => $ data_string ,
CURLOPT_HTTPHEADER => array (
"授权:Bearer fnwb5i8z / XXXXXXXXX" ,
" cache-control:no-cache" ,
" content-length:91" ,
" content-type:application / json" ,
" postman-token:80d5c9a7-55d2-3113-319a-558a948f6b42"
) ,
) ) ;
$ response = curl_exec ( $ curl < span style ="color:blue; font-family:monospace; font-size:13.3333px; white-space:nowrap">) ;
$ err = curl_error ( $ curl < span style ="color:blue; font-family:monospace; font-size:13.3333px; white-space:nowrap">) ;
curl_close ( $ curl < span style ="color:blue; font-family:monospace; font-size:13.3333px; white-space:nowrap">) ;
?>
<?php
$data = array(
'Inputs' => array(
'Input1' => array(array(
'Frequencia' => "30",
'Vazao' => "1",
'Resultado' => "",
),
),
),
'GlobalParameters' => new StdClass(),
);
$data_string = json_encode($data);
echo $data_string;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://ussouthcentral.services.azureml.net/XXXXXXXXXX",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
//CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $data_string,
CURLOPT_HTTPHEADER => array(
"authorization: Bearer fnwb5i8z/XXXXXXXXX",
"cache-control: no-cache",
"content-length: 91",
"content-type: application/json",
"postman-token: 80d5c9a7-55d2-3113-319a-558a948f6b42"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
?>
我哪里错了,拜托?
Where am I wrong, please?
推荐答案
你好,
你能不能在看到此错误之前,请告诉我们您使用的是哪个教程或文档?
Could you please let us know which tutorial or doc are you using before seeing this error?
从错误看,JSON数据似乎未作为Web服务正文的一部分传递要求服务。
From the error it looks like the JSON data is not passed as part of the body in your web service request to the service.
-Rohit
这篇关于Azure ML使用Web服务PHP Curl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!