मुझे कुछ पोस्ट पैराम्स के साथ एक सर्वर पर एक फ़ाइल पोस्ट करना है। प्रलेखन मैं इस सर्वर व्यवस्थापक से प्राप्त क्या पोस्ट अनुरोध तरह देखने के लिए माना जाता है का एक उदाहरण दिखाता (* नोट पोस्ट "मल्टीपार्ट/एक्स-api-रिमोट एकीकरण" के लिए कस्टम सामग्री प्रकार):PHP कर्ल पोस्ट; कस्टम सामग्री-प्रकार शीर्षलेख
POST /gateway/remote_send HTTP/1.0
Content-Type: multipart/x-api-remote-integration; boundary=ABC1234
Content-Length: 323
--ABC1234
Content-Type: application/x-www-form-urlencoded
profile_name=username&profile_pw=password1234&attached_type=action_1
--ABC1234
Content-Type: text/csv
Content-Disposition: attachment; filename="attachment.csv"
row1
row2
row3
--ABC1234--
<?php
function post(){
$base_api_url = "https://hostserver.com/gateway/remote_send";
$filename = realpath("/home/username/tests/test1234qwerty.csv");
$payload['profile_name'] = "username";
$payload['profile_pw'] = 'password1234';
$payload['attached_type'] = 'action_1';
$payload['filename'] = "@" . $filename . ";type=text/csv;";
$curl_options = array(
CURLOPT_URL => $base_api_url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query($payload),
CURLOPT_HTTP_VERSION => 1.0,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_VERBOSE => true,
CURLOPT_HEADER => false,
);
$curl = curl_init();
curl_setopt_array($curl, $curl_options);
$result = curl_exec($curl);
curl_close ($curl);
echo $result;
}
post();
मैं क्या सर्वर से वापस प्राप्त कर रहा से, ऐसा लगता है कि पोस्ट क्षेत्रों ठीक से प्राप्त किया जा रहा है:
नीचे php कोड है। हालांकि यह वह फ़ाइल है जिसे प्राप्त नहीं किया जा रहा है। मुझे यकीन नहीं है कि मैंने क्या गलत किया है। किसी इनपुट की काफी सराहना की जाती है।
संपादित करें: शब्दाडंबरपूर्ण प्रतिक्रिया अटैच किया जा रहा:
* About to connect() to hostserver.com port 443 (#0)
* Trying x.x.x.x... * connected
* successfully set certificate verify locations:
* CAfile: none
CApath: /etc/ssl/certs
* SSL connection using DHE-RSA-AES256-SHA
* ******** REDACTED ************
* SSL certificate verify ok.
> POST /gateway/remote_send HTTP/1.0
Host: hostserver.com
Accept: */*
Content-Length: 110
Content-Type: application/x-api-remote-integration
* upload completely sent off: 110out of 110 bytes
< HTTP/1.1 200 OK
< Date: Mon, 19 Aug 2013 16:00:38 GMT
< Server: Apache/2.2.15 (Red Hat)
< Pragma: no-cache
< CacheControl: no-cache
< Cache-Control: no-cache
< Expires: -1
< Connection: close
< Content-Type: multipart/x-api-remote-integration; boundary=remote_send-52124126
<
* Closing connection #0
HTTP/1.1 200 OK
Date: Mon, 19 Aug 2013 16:00:38 GMT
Server: Apache/2.2.15 (Red Hat)
Pragma: no-cache
CacheControl: no-cache
Cache-Control: no-cache
Expires: -1
Connection: close
Content-Type: multipart/x-vcg-remote-api; boundary=remote_send-52124126
--remote_send-52124126
Content-Type: application/x-www-form-urlencoded
result=invalid_filename
--remote_send-52124126--
मैं उपयोगकर्ता नाम जानते हैं और पीडब्लू डेटा सर्वर द्वारा सही पढ़ा जा रहा है के रूप में मैं गलत जानकारी के साथ परीक्षण किया और बदले क्रेडेंशियल त्रुटि दिखाई देती है।
अपनी जड़ से अपना कोड चलाने का प्रयास करें और '$ filename = realpath (" test/test1234qwerty.csv ") का उपयोग करें; 'देखें कि क्या इससे मदद मिलती है। किसी फ़ोल्डर नाम के साथ-साथ उस प्रकार के पथ का उपयोग करते समय '/' का उपयोग करते समय मुझे एक ही समस्या थी। –
त्वरित उत्तर और सुझाव के लिए धन्यवाद। मैंने बस कोशिश की और दुर्भाग्य से मैं अभी भी फ़ाइल संलग्नक के संबंध में एक ही प्रतिक्रिया देख रहा हूं। – foureight84
आपका स्वागत है। क्षमा करें, मुझे संदेह है कि मैं और मदद कर सकता हूं। मैं आपको शुभकामनाएं देता हूं, चीयर्स –