2014-05-07 93 views
0

這是什麼代碼的PHP中相當於:翻譯成PHP捲曲

curl -X PUT \ 
    -H "X-Parse-Application-Id: 4zcn5cCjKV8zYqoaHcasKFyUBxPB2qP7NYOZhMnw" \ 
    -H "X-Parse-REST-API-Key: GHHLNoICIZFXkD59QAwbDRVUd4JeSU4hVpBFq2md" \ 
    -H "Content-Type: application/json" \ 
    -d '{"score":73453}' \ 
    https://api.parse.com/1/classes/GameScore/Ed1nuqPvcm 

編輯:

     $url = 'https://api.parse.com/1/classes/' . $table_name . '/Jwqe23ls'; 
         $headers = array( "Content-Type: application/json", 
              "X-Parse-Application-Id: " . $appId, 
              "X-Parse-REST-API-Key: " . $restKey, 
              "X-HTTP-Method-Override: PUT"); 
         $objectData = '{"number":"4"}'; 
         $rest = curl_init(); 
         curl_setopt($rest,CURLOPT_URL,$url);     
         curl_setopt($rest,CURLOPT_POSTFIELDS, $objectData); 
         curl_setopt($rest,CURLOPT_HTTPHEADER,$headers); 
         curl_setopt($rest,CURLOPT_RETURNTRANSFER, true); 
         $response = curl_exec($rest); 
         echo $response; 
         curl_close($rest); 

現在,它的作品...

回答

0

如果你想PUT,像這樣做:

curl_setopt($ch, CURLOPT_PUT, true); 

此外,在我看來score:73453number:4不同,但在現階段可能不重要。

+0

是的,那不重要。現在我得到:{「code」:107,「error」:「invalid json:」} – mgulan

+0

在這種情況下,這可能很重要。這個消息似乎表明請求本身沒問題,但API在解析你的json時遇到了麻煩。這可能是因爲格式不正確,但也可能是因爲它沒有包含正確的字段,或者它使用錯誤的編碼發送。 – GolezTrol

+0

看看我的編輯。由於某種原因,它現在可以工作,但沒有與CURLOPT_PUT ... – mgulan