创建了一个PHP LARAVEL API,该API将使用aspx端点发布值。当我发布值时,我得到一个
FORM ERROR : Value cannot be null. Parameter name: String
从终点开始。
我测试了我的发布字段值,当我使用端点和浏览器添加值时,我得到了端点的响应,但是当我在控制器中使用cURL时,我收到了FORM错误
我的API控制器
if(!empty($postFields)){
$fields_string = "";
foreach($postFields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
$fields = rtrim($fields_string, '&');
$this_ch = curl_init();
$headers[] = "Connection: Keep-Alive";
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($this_ch, CURLOPT_URL, "http://example/test.aspx");
curl_setopt($this_ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this_ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($this_ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($this_ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($this_ch, CURLOPT_POST, TRUE);
curl_setopt($this_ch, CURLOPT_POSTFIELDS, $fields);
//curl_setopt($this_ch, CURLINFO_HEADER_OUT, 1);
$result = curl_exec($this_ch);
echo curl_error($this_ch);
$info = curl_getinfo($this_ch);
//var_dump($info);
curl_close($this_ch);
return $result;
}