Wie simulieren browser Formular-POST-Methode über PHP/cURL

Ich versuche zu simulieren, browser mit POST Methode mit PHP/cURL.
Als ich sah, dass live Http header zeigt Content-Type: multipart/form-data.

Checkte ich über das internet, wo es wurde vorgeschlagen, dass cURL senden multipart/form-data wenn ein custom-Header angegeben wird, um Content-Type: multipart/form-data.

$headers = array(
    'Content-Type' => 'multipart/form-data; boundary='.$boundary
);

Diese hat bei mir nicht funktioniert entweder, wenn ich print_r(curl_getinfo()) es zeigte

[content_type] => text/html; charset=UTF-8

Was bedeutet, dass cURL schickte einen Standard-Header

Ich habe auch gelesen, dass das senden/hochladen von Dateien mit cURL wird dazu führen, dass Daten zu senden als multipart/form-data. Ich habe eine Datei, die curl hochgeladen aber wenn ich wieder ran curl_getinfo ich habe [content_type] => text/html; charset=UTF-8

$data_array = array("field" => "@c:\file_location.txt");

Habe ich auch versucht zu Lesen, den Inhalt einer Datei, so dass die einzige Sache, die gesendet werden würde, Inhalte, die NICHT ANGEHÄNGT DATEI aber das hat nicht funktioniert für mich curl_getinfo zeigt [content_type] => text/html; charset=UTF-8.

$data_array = array("field" => "<c:\file_location.txt"); //note  @ replaced with <

Vermisse ich hier etwas?

Dies ist der referer

url

 
POST somepath HTTP/1.1 
Host: www(dot)domain(dot)com 
User-Agent: Mozilla/5.0 (Windows) Gecko/13081217 Firefox/3 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Language: en-us,en;q=0.5 
Accept-Encoding: gzip,deflate 
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 
Keep-Alive: 300 
Connection: keep-alive 
Referer: url/some-file.php 

Content-Type: multipart/form-data; boundary=--------------------------$Grenze 
Content-Length: $some_number 
----------------------------$Grenze 
Content-Disposition: form-data; name="$some_Value1" 

$some_text1 
----------------------------$Grenze 
Content-Disposition: form-data; name="$some_Value2" 

$some_text2 
----------------------------$Grenze 
Content-Disposition: form-data; name="$some_Value3" 

$some_text3 
----------------------------$Grenze 
Content-Disposition: form-data; name="$some_Value4" 

$some_text4 
----------------------------$Grenze 
Content-Disposition: form-data; name="$some_Value5" 

$some_text5 
----------------------------$Grenze 
Content-Disposition: form-data; name="$some_Value6" 

$some_text6 
----------------------------$Grenze 
Content-Disposition: form-data; name="$some_Value7" 

$some_text7 
----------------------------$Grenze 
Content-Disposition: form-data; name="$some_Value8" 

$some_text8 
----------------------------$Grenze 
Content-Disposition: form-data; name="$some_Value9" 


----------------------------$Grenze 
Content-Disposition: form-data; name="$some_Value10" 


----------------------------$boundary-- 

Hier ist ein Stück code.

<?

//Include  files

set_time_limit(0);

include'body.php';
include'keyword.php';
include'bio.php';
include'summary.php';
include'headline.php';
include'category.php';
include'spin.php';
include'random-text.php';


$category = category();
$headline = headline() ;
$summary = summary();
$keyword = keyword();
$body = body();
$bio = bio();

$target="url";
$ref ="url_ref";
$c = "Content-Disposition: form-data; name=";
$boundary = "---------------------------".random_text();

$category = category();
$headline = headline() ;
$summary = summary();
$keyword = keyword();
$body = body();
$bio = bio();

//emulating content form as it appears on livehttp header

$data = "\r\n".$boundary."\r\n".$c."\"pen_id\"\r\n\r\n".$Auth_id."\r\n".$boundary."\r\n".$c."\"cat_id\"\r\n\r\n".category()."\r\n".$boundary."\r\n".$c."\"title\"\r\n\r\n".headline()."\r\n".$boundary."\r\n".$c."\"meta_desc\"\r\n\r\n".summary()."\r\n".$boundary."\r\n".$c."\"meta_keys\"\r\n\r\n".keyword()."\r\n".$boundary."\r\n".$c."\"content\"\r\n\r\n".body()."\r\n".$boundary."\r\n".$c."\"author_bio\"\r\n\r\n".bio()."\r\n".$boundary."\r\n".$c."\"allow_comments\"\r\n\r\ny\r\n".$boundary."\r\n".$c."\"id\"\r\n\r\n\r\n".$boundary."\r\n".$c."\"action\"\r\n\r\n\r\n".$boundary."--\r\n";


//inserting content into a file

$file = "C:\file_path.txt";
$fh = fopen($file, 'w+') or die("Can't open file");
fwrite($fh,$data);
fclose($fh);

//pulling out content from a file as multipart/form-data

 $data_array = array ("field" => "<C:\file_path.txt");

$headers = array (
                    'POST /myhome/article/new HTTP/1.1',
                    'Host: url',
                    'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.20) Gecko/20081217 Firefox/2.0.0.20 (.NET CLR 3.5.30729)',
                    'Accept: text/html,application/xhtml+xml,application/xml;q=0.9;q=0.8',
                    'Accept-Language: en-us,en;q=0.5',
                    'Accept-Encoding: gzip,deflate',
                    'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7',
                    'Keep-Alive: 300',
                    'Connection: keep-alive',
                    'Content-Type: multipart/form-data; boundary='.$boundary,
                    'Content-Length: '.strlen($data),

                  );



  # Create the cURL session

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $target);    //Define target site

    curl_setopt($ch, CURLOPT_POST,1);
    curl_setopt($ch, CURLOPT_HEADER, $headers); //No http head
    //curl_setopt($ch, CURLOPT_REFERER, $ref);
    curl_setopt($ch, CURLOPT_NOBODY, FALSE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);      //Return page in string
    curl_setopt($ch, CURLOPT_COOKIEJAR, "c:\cookie\cookies.txt");  //Tell cURL where to write
    curl_setopt($ch, CURLOPT_COOKIEFILE, "c:\cookie\cookies.txt"); //Tell cURL which cookies
    //curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "$data_array");
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);      //Follow redirects
    curl_setopt($ch, CURLOPT_MAXREDIRS, 4);

   # Execute the PHP/CURL session and echo the downloaded page
   $page = curl_exec($ch);


$err = curl_error($ch);
$info =curl_getinfo($ch);

   # Close the cURL session
    curl_close($ch);

print_r($err);
print_r($info);

?>
Siehe stackoverflow.com/search?q=post+curl
Balus... danke für den link, aber ich habe gesucht alle über das Netz für Tage ohne Erfolg... die links, die du gepostet hast nicht mein problem lösen
Ich habe nicht geschrieben alle links. Sie muss verwirrend sein, mich mit jemand anderem.

InformationsquelleAutor user283266 | 2010-02-28

Schreibe einen Kommentar