i want to upload file with send http request to php . i test php sides on server over and over , but when i send request with this code
private static void upload() {
File targetFile = new File("test.txt");
PostMethod filePost = new PostMethod("http://localhost/chat_upload/service/index.php/upload/do_upload");
try {
Part[] parts = {
new FilePart(targetFile.getName(), targetFile),
new StringPart("name", "userfile")
};
filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams()));
org.apache.commons.httpclient.HttpClient client = new org.apache.commons.httpclient.HttpClient();
// client.getHttpConnectionManager().getParams().setConnectionTimeout(50000);
int status = client.executeMethod(filePost);
if (status == HttpStatus.SC_OK) {
System.out.println("Upload complete, response=" + filePost.getResponseBodyAsString());
} else {
System.out.println("Upload failed, response=" + HttpStatus.getStatusText(status));
}
} catch (Exception ex) {
System.out.println(ex.fillInStackTrace());
} finally {
filePost.releaseConnection();
}
}
this method send file and print on console . when i run , server say : file not selected .
{i write php side , when file not selected , this error print}
how to fix this?