【发布时间】:2017-06-19 15:07:39
【问题描述】:
我试图从网站/服务器接收一些响应,我得到的回报是:
System.ArgumentException','Object of type \'System.DBNull\' cannot be converted to type \'System.String
我的 PHP 代码:
$url = 'website';
$fields = array('searchstring' => urlencode('solkrem'), 'menuID' => urlencode(0), 'genses' => urlencode('20170201178577A2F54'), 'removeimages' => urlencode(false));
function httpPost($url, $data)
{
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
echo "<br><br>";
$result = httpPost($url,$fields);
var_dump($result);
我也知道,当我通过 requestmaker.com 使用数据和 url 尝试它时,我得到了我想要的响应......
我的字段编码是否正确,或者可能是什么原因?
编辑:来自 requestmaker.com 的一些信息:
已发送请求标头:
POST xxxxx HTTP/1.1
Host: xxx.com
Accept: */*
Content-Type: text/html
Content-Length: 75
收到请求标头:
HTTP/1.1 200 OK
Date: Thu, 02 Feb 2017 14:03:20 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
Cache-Control: private
Expires: Thu, 02 Feb 2017 14:03:19 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 58300
编辑 3:
我发现,即使网站要求我使用 & 分隔符添加详细信息,如果这样,它也不会起作用,并且会产生同样的错误:
但是如果它看起来像这样,没有 & 分隔符,它可以工作。我不知道它是如何发送的,导致它的后端 PHP 在测试页面上。
另外,如果我不发送任何字段,它会给出与我遇到的错误相同的输出。
更新 4:
从他们的网站上,我看到他们发送的内容如下:
'searchstring=solkrem\r\nmenuID=0\r\ngenses=20170201178577A2F54\r\nremoveimages=false
这会做些什么吗?嗯。
【问题讨论】:
-
该错误是由其他系统生成的。它说您在期望字符串的变量中传递了一个空值(无)。查看您正在联系的系统的文档并相应地更改您的 POST。
-
感谢@Andy,但我不知道他们使用什么系统。
-
更新主题@AndyC
-
您不需要将
&放在字段之间。 http_build_query 会为你做到这一点 -
@AndyC 如果我不想要 & 怎么办?我可以删除构建并自己构建吗?还是?
标签: php asp.net curl cross-domain