私は MongoLabs api を使用して生活を簡素化しようとしてきましたが、ほとんどの場合、php と curl を使用してデータベースに更新をプッシュしようとするまでは機能していましたが、サイコロはありません。私のコードはこれに似ています:
$data_string = json_encode('{"user.userEmail": "USER_EMAIL", "user.pass":"USER_PASS"}');
try {
$ch = curl_init();
//need to create temp file to pass to curl to use PUT
$tempFile = fopen('php://temp/maxmemory:256000', 'w');
if (!$tempFile) {
die('could not open temp memory data');
}
fwrite($tempFile, $data_string);
fseek($tempFile, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
//curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
//curl_setopt($ch, CURLOPT_INFILE, $tempFile); // file pointer
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, DB_API_REQUEST_TIMEOUT);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string),
)
);
$cache = curl_exec($ch);
curl_close($ch);
} catch (Exception $e) {
return FALSE;
}
私の問題は、MongoLab の API にあるようです。コード ビットは完璧に機能しますが、labs は、渡すデータが 'Invalid object{ "user.firstName" :"Pablo","user.newsletter":"true"}: フィールドに格納されていることを通知するという事実を除いて、 db を持つことはできません。それらの中で。ファイルを渡してポストフィールドを使用しようとしましたが、どちらも機能しませんでした。
firefox の Poster プラグインでテストすると、値は正常に機能します。誰かが MongoLabs のことをよりよく理解しているなら、私はいくらかの啓発が大好きです. 前もって感謝します!