我試着去接受她從網站/服務器響應一些,和所有我得到的回報是:CURL對象不能轉換爲類型'System.String
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
EDIT 3:
我發現,即使該網站要求我添加詳細信息的& seper ATOR,它不會如果這樣的工作,同時會產生同樣的錯誤:
但如果它看起來像這樣,沒有&分隔符,它的工作原理。我不知道它是如何發送的,在測試頁面上導致它的後端PHP。
此外,如果我不發送任何字段,它會給出相同的輸出,因爲我有錯誤。
更新4:
從他們的網站上,我看到他們發送它想:
'searchstring=solkrem\r\nmenuID=0\r\ngenses=20170201178577A2F54\r\nremoveimages=false
將在該做些什麼?哼。
該錯誤是由其他系統生成的。它表示你在一個變量中傳遞一個null(沒有),它是一個字符串。查看您正在聯繫的系統的文檔並相應地更改POST。 – Andy
謝謝@Andy,但我不知道他們使用的是什麼系統。 – maria
已更新主題@AndyC – maria