2020-05-19 23:16:15 -07:00
|
|
|
package com.rusefi.tools.online;
|
|
|
|
|
2020-05-22 11:03:10 -07:00
|
|
|
import org.apache.http.HttpEntity;
|
|
|
|
import org.apache.http.HttpResponse;
|
|
|
|
import org.apache.http.client.HttpClient;
|
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
|
|
import org.apache.http.entity.mime.MultipartEntity;
|
|
|
|
import org.apache.http.entity.mime.content.FileBody;
|
|
|
|
import org.apache.http.entity.mime.content.StringBody;
|
|
|
|
import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
|
import org.apache.http.util.EntityUtils;
|
|
|
|
|
2020-05-19 23:16:15 -07:00
|
|
|
import java.io.*;
|
|
|
|
|
|
|
|
public class Online {
|
2020-05-22 11:03:10 -07:00
|
|
|
private static final String url = "https://rusefi.com/online/upload.php";
|
2020-05-19 23:16:15 -07:00
|
|
|
|
|
|
|
public static void upload(File xmlFile, String authTokenValue) throws IOException {
|
2020-05-22 11:03:10 -07:00
|
|
|
HttpClient httpclient = new DefaultHttpClient();
|
|
|
|
HttpPost httpPost = new HttpPost(url);
|
2020-05-19 23:16:15 -07:00
|
|
|
|
2020-05-22 11:03:10 -07:00
|
|
|
FileBody uploadFilePart = new FileBody(xmlFile);
|
|
|
|
MultipartEntity reqEntity = new MultipartEntity();
|
|
|
|
reqEntity.addPart("upload-file", uploadFilePart);
|
2020-05-22 11:25:03 -07:00
|
|
|
reqEntity.addPart("rusefi_token", new StringBody(authTokenValue));
|
2020-05-19 23:16:15 -07:00
|
|
|
|
2020-05-22 11:03:10 -07:00
|
|
|
httpPost.setEntity(reqEntity);
|
2020-05-19 23:16:15 -07:00
|
|
|
|
2020-05-22 11:03:10 -07:00
|
|
|
HttpResponse response = httpclient.execute(httpPost);
|
|
|
|
System.out.println(response);
|
2020-05-19 23:16:15 -07:00
|
|
|
|
2020-05-22 11:03:10 -07:00
|
|
|
HttpEntity entity = response.getEntity();
|
|
|
|
String responseString = EntityUtils.toString(entity, "UTF-8");
|
|
|
|
System.out.println(responseString);
|
2020-05-19 23:16:15 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|