Ciao a tutti!
sto sviluppando un programma che mi consenta di inviare automaticamente dei dati su ebay, dal loro supporto ho ottenuto il modello della richiesta HTTP da effettuare per inoltrare i dati direttamente:
codice:
POST /path/to/upload/script HTTP/1.0
Connection: Keep-Alive
User-Agent: My Client App v1.0
Host: https://bulksell.ebay.com/ws/eBayISA...ExchangeUpload
Content-type: multipart/form-data; boundary=THIS_STRING_SEPARATES
Content-Length: 256
--THIS_STRING_SEPARATES
Content-Disposition: form-data; name="token"
12345678987654321
--THIS_STRING_SEPARATES
Content-Disposition: form-data; name="file";
filename="listings.csv"
Content-Type: text/csv
... contents of listings.csv ...
--THIS_STRING_SEPARATES-
ho cercato di realizzare la richiesta in questo modo, leggendo i contenuti del file che il mio programma ha preparato in precedenza, ma ottengo un errore 400 come risposta:
ho notato che non riesco a inserire quell' "/path/to/upload/script HTTP/1.0" a fianco a "POST"
codice:
try{
URL url = new URL("https://bulksell.ebay.com/ws/eBayISAPI.dll?FileExchangeUpload");
HttpURLConnection connessione = (HttpURLConnection)url.openConnection();
connessione.setDoInput (true);
connessione.setDoOutput (true);
connessione.setUseCaches (false);
connessione.setRequestMethod("POST");
connessione.setRequestProperty("Connection", "Keep-Alive");
connessione.setRequestProperty("User-Agent", "BdMButler");
connessione.setRequestProperty("Host", "https://bulksell.ebay.com/ws/eBayISAPI.dll?FileExchangeUpload");
connessione.setRequestProperty("Content-type", "multipart/form-data; boundary=THIS_STRING_SEPARATES");
//apro lo stream output
DataOutputStream dos = new DataOutputStream(connessione.getOutputStream());
dos.writeBytes("--THIS_STRING_SEPARATES\r\n");
dos.writeBytes("Content-Disposition: form-data; name=\"token\"\r\n");
dos.writeBytes("12345678987654321\r\n");
dos.writeBytes("--THIS_STRING_SEPARATES\r\n");
dos.writeBytes("Content-Disposition: form-data; name=\"file\";\r\n");
dos.writeBytes("filename=\"listings.csv\"\r\n");
dos.writeBytes("Content-Type: text/csv\r\n");
//legge il csv
FileInputStream fileInputStream = new FileInputStream( new File("modificheEbay.csv") );
int bufferSize = fileInputStream.available();
byte[] buffer = new byte[bufferSize];
int bytesRead = fileInputStream.read(buffer, 0, bufferSize);
while(bytesRead>0) {
dos.write(buffer, 0, bufferSize);
bufferSize = fileInputStream.available();
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
}
fileInputStream.close();
dos.writeBytes("\r\n");
dos.writeBytes("--THIS_STRING_SEPARATES-\r\n\r\n");
//legge la risposta dal server
BufferedReader inStream = new BufferedReader(new InputStreamReader ( connessione.getInputStream()));
String str;
while (( str = inStream.readLine()) != null) {
System.out.println("Server response is: "+str);
System.out.println("");
}
inStream.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
qualcuno ha idea di dove sia il mio errore ed eventualmente come risolverlo?