0

多くの方法を試した後、このコードを修正するのを手伝ってくれませんか。

常に戻る{"code":201,"error":"missing user password"}

<?php 
$APPLICATION_ID = "XXXXXXXXXXXXXx"; 
$REST_API_KEY = "XXXXXXXXXXXX"; 
$url = 'https://api.parse.com/1/login';

$headers = array(
'X-Parse-Application-Id: ' . $APPLICATION_ID,
'X-Parse-REST-API-Key: ' . $REST_API_KEY,
//option 1
//urlencode('username=xxxxxx'),
//urlencode('password=xxxxxxx'),
);

$curl = curl_init($url); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($curl, CURLOPT_TIMEOUT, '3'); 
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); 
//option 2 
//curl_setopt($curl, CURLOPT_ENCODING, 'username=xxxxx'); 
//curl_setopt($curl, CURLOPT_ENCODING, 'password=xxxxxxx');

$content = curl_exec($curl); curl_close($curl);

print $content

?>

PHPを使用したログインです

前もって感謝します!

4

2 に答える 2

0

このデータを次のように渡す必要があります。

$data = array(
   'username' => urlencode('XXXXX'),
   'password' => urlencode('XXXXXXX')
);

// URL-IFY
foreach($data as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');

次に、次のようにデータを渡します。

curl_setopt($curl,CURLOPT_POST, count($fields));
curl_setopt($curl,CURLOPT_POSTFIELDS, $fields_string);
于 2012-10-25T08:33:29.453 に答える
0

Kennyが指摘したように、POST変数を次の形式で送信する必要があります。私はこれにhttp_build_queryを使用するのが好きです:

$postData = array(
    'username' => 'Test',
    'password' => 'Tester'
);

curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($postData));

HTTP認証を扱っている場合:

curl_setopt($curl, CURLOPT_USERPWD, 'username:password');
于 2012-10-25T08:40:45.343 に答える