2017-02-05 69 views
0

你好,我有這個工作CURL發佈請求我希望用guzzle重新編碼。但我在400壞請求上失敗。任何人都看到我在做什麼錯:需要幫助將一個PHP CURL腳本轉換爲垃圾

$response = $this->getHttpClient()->post(
     'https://login.eveonline.com/oauth/token', [ 
     'headers' => [ 
      'Authorization' => 'Basic '.base64_encode(
       env('EVEONLINE_CLIENT_ID').':'.env('EVEONLINE_CLIENT_SECRET') 
      ) 
     ], 
     'grant_type' => 'refresh_token', 
     'refresh_token' => $refresh_token, 
    ]); 

    return json_decode($response->getBody()->getContents(), true); 

    /* 
    $c = curl_init(); 
    $cver = curl_version(); 
    $contact = '[email protected]';  
    curl_setopt($c, CURLOPT_URL, 'https://login.eveonline.com/oauth/token'); 
    curl_setopt($c, CURLOPT_USERAGENT, "asite/admin (curl/{$cver['version']}; {$contact})"); 
    curl_setopt($c, CURLOPT_SSL_VERIFYPEER, FALSE); 
    curl_setopt($c, CURLOPT_SSL_VERIFYHOST, FALSE); 
    curl_setopt($c, CURLOPT_POST, true); 
    curl_setopt($c, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($c, CURLOPT_POSTFIELDS, http_build_query([ 
     'grant_type' => 'refresh_token', 
     'refresh_token' => $refresh_token, 
    ])); 
    curl_setopt($c, CURLOPT_HTTPHEADER, [ 'Authorization: Basic '.base64_encode(
     env('EVEONLINE_CLIENT_ID').':'.env('EVEONLINE_CLIENT_SECRET') 
    ) ]); 

    $rawjson = curl_exec($c); 
    return json_decode($rawjson, true); 
    */ 

迴應: 客戶端錯誤:POST https://login.eveonline.com/oauth/token導致了400 Bad Request響應: { 「錯誤」: 「INVALID_REQUEST」, 「ERROR_DESCRIPTION」: 「未知grant_type」}

+0

什麼版本的Guzzle? – ceejayoz

+0

https://github.com/guzzle/psr7 1.3.1發佈 –

回答

0

修復了它已經對不便帶來的不便:

$response = $this->getHttpClient()->post(
     'https://login.eveonline.com/oauth/token', [ 
     'headers' => [ 
      'Authorization' => 'Basic '.base64_encode(
       env('EVEONLINE_CLIENT_ID').':'.env('EVEONLINE_CLIENT_SECRET') 
      ) 
     ], 
     'json' => [ 
      'grant_type' => 'refresh_token', 
      'refresh_token' => $refresh_token, 
     ]   
    ]);