यदि आपको प्रतिक्रिया से ज़िप फ़ाइल की आवश्यकता है तो मुझे लगता है कि आप कर्ल प्रतिक्रिया को बचाने के लिए केवल एक टीएमपी फ़ाइल लिख सकते हैं, और वर्कअराउंड के रूप में स्ट्रीम कर सकते हैं: मल्टीपार्ट कर्ल के साथ कभी कोशिश नहीं की, लेकिन मुझे लगता है कि इसे काम करना चाहिए ।
$fh = fopen('/tmp/foo', 'w');
$cUrl = curl_init('http://example.com/foo');
curl_setopt($cUrl, CURLOPT_FILE, $fh); // redirect output to filehandle
curl_exec($cUrl);
curl_close($cUrl);
fclose($fh); // close filehandle or the file will be corrupted
आप केवल एक प्रतिक्रिया
curl_setopt($cUrl, CURLOPT_HTTPHEADER, array('Accept: application/xml'));
//That's a workaround since there is no available curl option to do so but http allows that
के रूप में स्वीकार करने के लिए एक्सएमएल हेडर
curl_setopt($cUrl, CURLOPT_HEADER, FALSE);
अक्षम करें और विकल्प जोड़ने के लिए चाहते हो सकता है आप कुछ भी लेकिन प्रतिक्रिया की एक्सएमएल भाग की जरूरत नहीं है [संपादित करें]
अंधेरे में एक शॉट ... आप इन के साथ परीक्षण कर सकते हैं curlopt सेटिंग्स के रूप में उल्लेख किया है मैं अपने curled पृष्ठों एक बहुखण्डीय प्रपत्र डेटा के साथ प्रतिक्रिया करने के लिए नहीं मिल सकता है इन मदद modifiying अगर कुछ भी
$headers = array (
'Content-Type: multipart/form-data; boundary=' . $boundary,
'Content-Length: ' . strlen($requestBody),
'X-EBAY-API-COMPATIBILITY-LEVEL: ' . $compatLevel, // API version
'X-EBAY-API-DEV-NAME: ' . $devID,
'X-EBAY-API-APP-NAME: ' . $appID,
'X-EBAY-API-CERT-NAME: ' . $certID,
'X-EBAY-API-CALL-NAME: ' . $verb,
'X-EBAY-API-SITEID: ' . $siteID,
);
$cUrl = curl_init();
curl_setopt($cUrl, CURLOPT_URL, $serverUrl);
curl_setopt($cUrl, CURLOPT_TIMEOUT, 30);
curl_setopt($cUrl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($cUrl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($cUrl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($cUrl, CURLOPT_POST, 1);
curl_setopt($cUrl, CURLOPT_POSTFIELDS, $requestBody);
curl_setopt($cUrl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cUrl, CURLOPT_FAILONERROR, 0);
curl_setopt($cUrl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($cUrl, CURLOPT_HEADER, 0);
curl_setopt($cUrl, CURLOPT_USERAGENT, 'ebatns;xmlstyle;1.0');
curl_setopt($cUrl, CURLOPT_HTTP_VERSION, 1); // HTTP version must be 1.0
$response = curl_exec($cUrl);
if (!$response) {
print "curl error " . curl_errno($cUrl) . PHP_EOL;
}
curl_close($cUrl);
[संपादित द्वितीय]
यह सिर्फ एक कोशिश है देखने के लिए,।तो यहाँ मेरे साथ कोमल हो;)
$content_type = ""; //use last know content-type as a trigger
$tmp_cnt_file = "tmp/tmpfile";
$xml_response = ""; // this will hold the "usable" curl response
$hidx = 0; //header index.. counting the number of different headers received
function read_header($cUrl, $string)// this will be called once for every line of each header received
{
global $content_type, $hidx;
$length = strlen($string);
if (preg_match('/Content-Type:(.*)/', $string, $match))
{
$content_type = $match[1];
$hidx++;
}
/*
should set $content_type to 'application/xop+xml; charset=utf-8; type="text/xml"' for the first
and to 'application/zip' for the second response body
echo "Header: $string<br />\n";
*/
return $length;
}
function read_body($cUrl, $string)
{
global $content_header, $xml_response, $tmp_cnt_file, $hidx;
$length = strlen($string);
if(stripos ($content_type , "xml") !== false)
$xml_response .= $string;
elseif(stripos ($content_type, "zip") !== false)
{
$handle = fopen($tmp_cnt_file."-".$hidx.".zip", "a");
fwrite($handle, $string);
fclose($handle);
}
/*
elseif {...} else{...}
depending on your needs
echo "Received $length bytes<br />\n";
*/
return $length;
}
और निश्चित रूप से उचित curlopts
// Set callback function for header
curl_setopt($cUrl, CURLOPT_HEADERFUNCTION, 'read_header');
// Set callback function for body
curl_setopt($cUrl, CURLOPT_WRITEFUNCTION, 'read_body');
मत भूलना नहीं स्मृति समस्याओं के कारण एक चर को कर्ल प्रतिक्रिया को बचाने के लिए, सेट उम्मीद है कि आपको बस किसी भी तरह से $ xml_response में होना चाहिए।
//$response = curl_exec($cUrl);
curl_exec($cUrl);
और आप आप इस परिदृश्य में tmp/tmpfile-2
के साथ शुरू बनाया अस्थायी फ़ाइलों $xml_response
का उल्लेख कर सकते हैं और अपने कोड पार्स करने के लिए। दोबारा, मैं किसी भी तरह से ऊपर दिए गए कोड का परीक्षण करने में सक्षम नहीं हूं। तो यह काम हो सकता है नहीं (लेकिन यह imho चाहिए;))
[संपादित करें तृतीय]
कहते हैं कि हम आने वाले सभी डेटा एक और (जावक) धारा के लिए सीधे लिखने के लिए कर्ल चाहते हैं, इस मामले में एक गर्तिका कनेक्शन
मैं अगर यह इस तरह ही आसान है यकीन नहीं है:
$fs = fsockopen($host, $port, $errno, $errstr);
$cUrl = curl_init('http://example.com/foo');
curl_setopt($cUrl, CURLOPT_FILE, $fs); // redirect output to sockethandle
curl_exec($cUrl);
curl_close($cUrl);
fclose($fs); // close handle
बाकी
हमें बस थोड़ी चाल के साथ हमारे जाना जाता लिखने और हैडर कार्यों का उपयोग करना होगा
//first open the socket (before initiating curl)
$fs = fsockopen($host, $port, $errno, $errstr);
// now for the new callback function
function socket_pipe($cUrl, $string)
{
global $fs;
$length = strlen($string);
fputs($fs, $string); // add NOTHING to the received line just send it to $fs; that was easy wasn't it?
return $length;
}
// and of course for the CURLOPT part
// Set callback function for header
curl_setopt($cUrl, CURLOPT_HEADERFUNCTION, 'socket_pipe');
// Set the same callback function for body
curl_setopt($cUrl, CURLOPT_WRITEFUNCTION, 'socket_pipe');
// do not forget to
fclose($fs); //when we're done
बात यह है कि परिणाम संपादित नहीं किया जा रहा है और इसे $fs
पर पाइप करने से यह आवश्यक हो जाएगा कि अपाचे एक निश्चित बंदरगाह पर सुन रहा है जिसे आप अपनी स्क्रिप्ट को असाइन करते हैं। या आप के बाद fsockopen
fputs($fp, "POST $path HTTP/1.0\n"); //where path is your script of course
शायद आप एक एमआईएमई मेल पार्सिंग लाइब्रेरी का उपयोग कर सकते हैं। Http://stackoverflow.com/questions/1238642/how-to-extract-mail-atachment-with-php/1240048#1240048 – Barmar
यह एक शुद्ध 'फॉर्म-डेटा' है और इसमें मेल हेडर नहीं हैं, लेकिन मैं कोशिश करो। वास्तव में कोशिश करने से पहले मैं इसे समाधान के बहुत करीब देखता हूं। – Vicary
टिप्पणी के लिए रेट किया गया क्योंकि चंद्र नव वर्ष समाप्त होने से पहले बक्षीस खत्म हो जाएगा, इससे पहले कि मुझे कार्यालय में कोड प्राप्त करने का मौका मिले। – Vicary