Hi, can somebody help me how to upload a file using HTTPS POST?
Printable View
Hi, can somebody help me how to upload a file using HTTPS POST?
Did you tried anything yet? At least search on Google?
Yes i have done little bit search on Google it is telling about JSSE(Java Secure Socket Extensions) i just want the steps that i need to do so that i can send Https requets to server
Do you want to workout on the server side or on the client side?
Could you please brief me basic steps that we have to fallow on both the side Server side as well as Client side
First of all you should learn about sockets. That's starting point you have to move ahead.
Right now i need some help to create SSL connection between client and server.
Are you writing the client? or the server?
This is well documented. What have you done so far (if anything)?
What specific problems are you having?
This is not a forum for finding packaged answers. We will help, but not do your homework. You learn nothing from cheating.
Use apache httpclient APIs
Note: when uploading to https web server, the web server's "public key certificate" should be present in the client machine's JRE's keystore file.
normally present in <jdkhome>\jre\lib\security\cacerts
here cacerts file is the keystore file
you need to import the certificate into this keystore file using keytool command
sample code;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class PostAFile {
private static String url =
"url to server, where you want to upload file";
public static void main(String[] args) throws IOException {
HttpClient client = new HttpClient();
PostMethod postMethod = new PostMethod(url);
client.setConnectionTimeout(8000);
// Send any XML file as the body of the POST request
File f = new File("students.xml");
System.out.println("File Length = " + f.length());
postMethod.setRequestBody(new FileInputStream(f));
postMethod.setRequestHeader("Content-type",
"text/xml; charset=ISO-8859-1");
int statusCode1 = client.executeMethod(postMethod);
System.out.println("statusLine>>>" + postMethod.getStatusLine());
postMethod.releaseConnection();
}
}
refer to: theserverside.com/tt/articles/article.tss?l=HttpClient_FileUpload