httpclient 获取和放置

发布于 2024-08-18 19:24:51 字数 315 浏览 5 评论 0 原文

这就是我想做的事情,并且需要一些帮助。

我有一个源网址和一个目标网址。我想要做的是将文件从源 url 复制到目标 url,但我想避免在再次上传文件之前在系统上本地复制该文件。

另外,我们必须获得内容长度,因为目标 api 需要它(它的自定义)。如果我使用 HttpUrlConnection 类,那么我可以得到它......但是据我所知,使用 java.net 进行除 GET 之外的任何操作都存在一些问题。 (源文件是巨大的图像/视频文件),所以我可以使用apache httpclient 3.1。但我该如何处理这个问题呢?

有什么想法吗?

-灰

here is what i want to do and need some help in it.

I have a source url and a destination url. what i want to do is copy a file from a source url to the destination url, but I want to avoid copying the file locally on my system before uploading the file again.

Also what is must to have is that we should get the content-length because the destination api requires it (its custom). If I use the HttpUrlConnection class then i can get that....but AFAIK there are some issues in using java.net for anything other than GET. (the source files are huge image/video files), so i can using apache httpclient 3.1. But how do i approach this?

any thoughts?

-Ash

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

送舟行 2024-08-25 19:24:51

您尝试过以下操作吗?

请参阅此教程

编辑

您应该能够使用 GetMethod.getResponseContentLenght (对应于 Content-Length 标头,如果提供)。

那么我建议您查看以下 PUT 方法之一: setRequestContentLenghtaddContentLenghtRequestHeader , setContentChunked

Did you try the following?

See this tutorial.

EDIT

You should be able to get the response size of the GET with GetMethod.getResponseContentLenght (which corresponds to the Content-Length header, if provided).

Then I suggest you look at one of the following for the PUT method: setRequestContentLenght, addContentLenghtRequestHeader, setContentChunked.

潇烟暮雨 2024-08-25 19:24:51

我想避免复制文件
上传之前在我的系统本地
再次查看文件

,您将不得不忍受它,因为这就是 HTTP 的工作原理。如果你想进行远程到远程的传输,你要么使用 HTTP 以外的协议(尽管我不知道有什么协议适合这种情况),要么在远程站点之一上远程执行一些软件执行转移。

I want to avoid copying the file
locally on my system before uploading
the file again

Well you're going to have to live with it, because that's how HTTP works. If you want to do remote-to-remote transfers, you're going to either use something other than HTTP (although I don't know of any protocol suitable for that), or remotely execute some software on one of the remote sites to perform the transfer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文