2016-08-08 87 views
1

我正嘗試在PHP中創建PUT調用。在PHP中使用curl創建PUT調用

當我在郵遞員所有的標題等,一切正常。但是當我嘗試在PHP中創建curl調用時,我超時了。從郵遞員

原始代碼:

PUT /rest/Google/save_google_token HTTP/1.1 
Host: mySite.cz 
Content-Type: application/json 
OAuth-token: bfb33249-4f9a-a89f-38aa-57a8487a6848 
Cache-Control: no-cache 
Postman-Token: bf2f9320-01e7-1e14-b431-657b5e8d58b5 

{ 
    "auth" : "4/NSzqsmIJabQaiwva1L7L1RBzK4M9yeRJuU9ScG24r5o" 
} 

我試圖在PHP中:

$urlApi = "http://mySite.cz/rest/Google/save_google_token"; 
$auth = $_GET['code']; 
$token = $_GET['state']; 

if (isset($auth) && isset($token)) { // we received the positive auth callback, get the token and store it 

    $data = array(
     'auth' => $auth, 
    ); 
    $data = json_encode($data); 

    $curl = curl_init($urlApi); 

    //for some reason, these queries do not work 
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); 
    curl_setopt($curl, CURLOPT_HEADER, false); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json',"OAuth-Token: $token")); 
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data); 
    $response = curl_exec($curl); 

    if (!$response) { 
     die("Connection Failure."); 
    } 
} 

回答

1

原來,我的服務器封鎖了自稱。 我只是改變

"http://mySite.cz/rest/Google/save_google_token" 

"https://127.0.0.1/rest/Google/save_google_token" 

,並添加

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 

這解決了這個問題。