Devo pubblicare un file su un server insieme a pochi parametri di post. La documentazione che ho ricevuto da questo server di amministrazione mostra un esempio di ciò che si suppone la richiesta POST per assomigliare (* NOTA il tipo di contenuto personalizzato per il POST "/ x-api-remote-integrazione multipart"):post di ricciolo PHP con allegato file; intestazione del tipo di contenuto personalizzato
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--
di seguito si riporta il codice PHP:
<?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();
da quello che sto ricevendo dal server, sembra che i campi pubblicare vengono ricevuti correttamente. Tuttavia è il file che non viene ricevuto. Non sono sicuro di cosa ho sbagliato. Qualsiasi input è molto apprezzato.
EDIT: Collegamento risposta Verbose:
* 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--
conosco il nome utente e pw dati vengono letti correttamente dal server come io ho provato con informazioni errate e ha ricevuto l'errore di credenziali, invece.
Provare a eseguire il codice dalla root e utilizzare '$ filename = realpath (" tests/test1234qwerty.csv "); vedere se questo aiuta. Ho avuto un problema simile prima di usare '/' davanti al nome di una cartella e usare quel tipo di percorso. –
Grazie per la rapida risposta e il suggerimento. L'ho appena provato e sfortunatamente vedo ancora la stessa risposta riguardo all'allegato di file. – foureight84
Prego. Scusa, dubito di poter essere di ulteriore aiuto. Ti auguro ogni bene, evviva –