2016-09-27 54 views
0

這裏是我的CURL例如,通過API作者提供:另一個捲曲C#轉換嘗試

$data = array("username" => "XX", "password" => "XX"); 
$data_string = json_encode($data); 
$ch = curl_init('https://<url excluded>'); 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 
//Attached the path to .CRT file 
curl_setopt($ch, CURLOPT_CAINFO, getcwd() ."/AddTrustExternalCARoot.crt"); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' 
. strlen($data_string)) 
); 
$result = curl_exec($ch); 
echo $result; 

方法應返回用於後續API調用使用的字母數字API密鑰。我所有使用WebClient和HttpRequest的嘗試都返回了400或403錯誤。

任何幫助,我可以弄清楚正確的C#庫和語法會很好。

+1

看看http://restsharp.org,它提供了你需要的一切 –

回答

0

使用RestSharp並澄清與API提供商的通信要求,使我能夠正常工作。感謝您的建議。