我正在尝试模拟这个 java 代码
public static void uploadFile(String filename, String systemID){
try{
String createNew = "false";
//check for backup files to know if we should make a new file on the server
File f = new File(filename + ".1");
if(f.exists()){
createNew = "true";
f.delete();
}
HttpURLConnection httpUrlConnection = (HttpURLConnection)new URL(uploadURL).openConnection();
httpUrlConnection.setDoOutput(true);
httpUrlConnection.setRequestMethod("POST");
httpUrlConnection.setRequestProperty("Content-encoding", "deflate");
httpUrlConnection.setRequestProperty("Content-type", "application/octet-stream");
java.io.OutputStream os = httpUrlConnection.getOutputStream();
Thread.sleep(1000);
String fileData = IOUtils.toString(new FileReader(filename));
String request = "filedata=" + fileData + "&filename=" + filename + "&systemid=" + systemID + "&createNew=" + createNew;
DeflaterOutputStream deflate = new DeflaterOutputStream(os);
deflate.write(request.getBytes());
deflate.flush();
deflate.close();
os.close();
BufferedReader in = new BufferedReader(new InputStreamReader(httpUrlConnection.getInputStream()));
String s = null;
while ((s = in.readLine()) != null) {
System.out.println(s);
}
in.close();
//fis.close();
}catch(Exception e){
e.printStackTrace();
}
static String uploadURL = "http://vp-creations.com/utilities/fileupload.php";
在使用请求的python中,我认为我错过了一些简单的东西,因为我无法从服务器获得正确的响应
import requests
url = 'http://vp-creations.com/utilities/fileupload.php'
files = {'file': open('C:\\etc\\guitartab.txt', 'rb')}
headers = {'Content-encoding': 'deflate', 'Content-type': 'application/octet-stream'}
payload = {'filedata=': 'foo', 'filename=': 'bar', 'systemid=' : 'fooe', 'createNew=' : 'false'}
r = requests.post(url, files=files, headers=headers, data=payload)
我不断收到来自服务器的响应是 {"response":"error","comment":"missing at least one parameter"}' 有什么帮助吗?