在 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 的角色,它将包括一个 Stream。
谢谢!
编辑:发现这个Using java.net.URLConnection to fire and handle HTTP requests但它似乎太复杂了......希望有一种更简单的方法来做到这一点?