setRequestEntity

hi,

i'm trying to follow the example code down here which I got from http://www.theserverside.com/articles/article.tss?l=HttpClient_FileUpload

the problem is, the postMethod.setRequestBody(new FileInputStream(f));

is deprecated. I checked the API docs and it says to use setRequestEntity(RequestEntity)

instead.

The setRequestBody either receives java.io.InputStream body or java.lang.String body as the argument, but the setRequestEntity receives RequestEntity as the argument.

In the context of the example source code, how do I use it?

Any help is greatly appreciated. Thanks

Here's the source 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;

publicclass PostAFile{

privatestatic String url =

"http://localhost:8080/HttpServerSideApp/GetRequest.jsp";

publicstaticvoid 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();

}

}

[2616 byte] By [imin83a] at [2007-10-2 8:54:45]
# 1
did you bother to look at these docs?[url] http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/methods/InputStreamRequestEntity.html[/url]which provide implementation for RequestEntity.kind regardswalken
walken16a at 2007-7-16 22:58:43 > top of Java-index,Java Essentials,Java Programming...
# 2
ouch... i missed that one...thanks a lot.. i'll try looking into that
imin83a at 2007-7-16 22:58:43 > top of Java-index,Java Essentials,Java Programming...
# 3
:)kind regardswalken
walken16a at 2007-7-16 22:58:43 > top of Java-index,Java Essentials,Java Programming...