2016-08-08 8 views
1

PHPでPUT呼び出しを作成しようとしています。PHPでcurlを使用してPUT呼び出しを作成する

私は郵便配達ですべてのヘッダーなどを作ると、すべて正常に動作します。しかし、PHPでカールコールを作成しようとするとタイムアウトします。

郵便配達員からの生コード:PHPで

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" 
} 

私の試み:

$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

それは私のサーバーが自分自身を呼び出してブロックされていたことが、判明しました。 私はちょうど

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

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

を変更し、

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 

追加これは、問題を解決しました。

関連する問題