在c#中,我可以这样做:
HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
request.Method = "POST";
request.ContentType = "application/octet-stream";
request.ContentLength = fileToSend.Length;
request.Timeout = 2000000000;
using (Stream requestStream = request.GetRequestStream())
{
// Send the file as body request.
requestStream.Write(fileToSend, 0, fileToSend.Length);
requestStream.Close();
}我正在寻找一个类似的对象,我可以在Java中使用它来扮演HttpWebRequest的角色,它将包括一个流。
谢谢!
编辑:找到了这个Using java.net.URLConnection to fire and handle HTTP requests,但它似乎太复杂了……希望有一种更简单的方法来做到这一点?
发布于 2013-04-09 19:48:59
我建议您使用Apache HTTP Client (http://hc.apache.org/httpclient-3.x/features.html)。
如果只需要从某些资源查询信息,那么标准JDK就足够了:
java.net.URL url = new java.net.URL("http://foo.bar");
URLConnection conn = url.openConnection();
//conn.getOutputStream() to place information
//conn.getInputStream() to read resourcehttps://stackoverflow.com/questions/11215727
复制相似问题