Bir POST isteği yapmak

0 Cevap php

I would like to know how to make a HTTP POST request like it's described there http://code.google.com/apis/documents/docs/3.0/developers_guide_protocol.html#UploadingMetadata (Creating an empty document). My code looks like this:

<?php

$headers = array(
    "POST /feeds/default/private/full HTTP/1.1",
    "Host: docs.google.com",
    "GData-Version: 3.0",
    "Content-Length: 287",
    "Content-Type: application/atom+xml"
);

$data = "<?xml version='1.0' encoding='UTF-8'?>";
$data .= "<entry xmlns='http://www.w3.org/2005/Atom'>";
$data .= "<category scheme='http://schemas.google.com/g/2005#kind'";
$data .= "term='http://schemas.google.com/docs/2007#document'/>";
$data .= "<title>new document</title>";
$data .= "</entry>";

$ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, "http://google.com/docs/feeds/default/private/full");
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, true);

$result = curl_exec($ch);

print_r($result);

?>

Orada ne oldu? Ben doğru isteği yapıyor muyum?

0 Cevap