2016-11-11 82 views
0

我正在构建一个GET请求来发送变量,它的工作原理没有变量,但没有。curl在php中获取请求

我建造它错了吗?

$curl = curl_init(); 
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1, 
    CURLOPT_URL => 'https://ws.mysite.com/outside.svc/AssessmentActivityInsert?/&userID=' . $userID . '&score=' . $percentile .'&assessmentID= '. $testID . ' &assessmentTitle= '. $testName .'\',', 
    CURLOPT_USERAGENT => 'sent from mysite' 
)); 
$resp = curl_exec($curl); 
curl_close($curl); 

回答

3

您的网址变更为:

CURLOPT_URL => 'https://ws.mysite.com/outside.svc/AssessmentActivityInsert/?userID=' . $userID . '&score=' . $percentile .'&assessmentID= '. $testID . '&assessmentTitle= '. $testName, 
  • ?是放错了地方
  • 你没有在第一个参数
  • &assessmentTitle= '. $testName .'\',',是错的需要&。它应该只是&assessmentTitle= '. $testName,
  • 和你CURLOPT_USERAGENT是无效的。
+0

的CURLOPT_USERAGENT应该如何? –

+0

我可以离开没有用户代理 –

+1

@BenjaminOats看看http://thisinterestsme.com/php-set-curl-user-agent/。大多数时候你不需要发送它,除非服务器需要(即确保你正在使用浏览器等) –