Java 上传小程序请求 [英] Java Upload Applet Request

查看:28
本文介绍了Java 上传小程序请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以给我看/链接一个简单的多部分表单数据,我可以转换为小程序的http post文件上传脚本吗?寻找一个对我轻松的人,我已经追求这个目标一个多月了,现在正需要这个.我对 Java 很陌生,在完成这个项目的过程中取得了几次小胜利,但我绝对需要这方面的帮助.

Can someone please show me/link a simple multipart form data, http post file upload script I can convert to an applet? Looking for someone that who will go easy on me, I've been after this goal for over a month now and just need this. I'm very new to java and have had several small victories on my way to finishing this project but I absolutely need help with this.

我已经有一些签名的脚本可以工作,所以我自己做了很多,但我在这里需要一个坏的.我只是很困惑.

I've already got a few signed scripts working, so I've done a lot on my own, but I need one here bad. I'm just so confused.

推荐答案

从您的小程序中执行 http 帖子的最简单方法是使用 Apache HTTP 客户端.您需要将 jar 文件添加到小程序的 classpath.一个简单的例子:

The easiest approach to do an http post from your applet is to use Apache HTTP Client. You'll need to add the jar file to your applet's classpath. A simple example:

HttpClient client = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://example.com/test");
MultipartEntity entity = new MultipartEntity();
entity.addPart("file1", new FileBody(new File("filetoUpload.jpg"), "application/jpg"));
post.setEntity(entity);
client.execute(post)
client.getConnectionManager().shutdown();

如果由于某种原因您不能使用 HTTP 客户端,您仍然可以使用 java.net.URL 来完成,但它要复杂得多:

If for some reason you cannot use HTTP Client you can still do it with java.net.URL but it's a lot more complicated:

使用 java.net.URLConnection 来触发和处理 HTTP 请求

这篇关于Java 上传小程序请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆