如何将文件发布到使用java的php(如html表单那样)?Java Post Post to PHP
1
A
回答
4
如果您只是需要生成HTTP POST,请检查HttpClient,特别是PostMethod。既然你说的是HTTP,服务器上的实现技术(在你的情况下,PHP)并不重要。
有一个例子here。
1
httpclient library包含您需要与Web服务器通信的所有工具。
2
事实上,这是可以做到只使用在JDK中的类一个职位,但正如其他人指出,它可能会更容易使用像的HttpClient库。
除了HttpClient,您还可以查看由RESTful框架(如Restlet和Jersey)提供的客户端Java库。虽然主要是为了与Web服务交互而设计的,但它们提供了对GET和POST的几乎任何事情的非常高级的抽象。
代码没有经过测试,甚至编译(可能不编译),但是这是有点儿八九不离十会,如果你想推出自己的,你会怎么做:
URL url = new URL("http://hostname/foo.php");
URLConnection connection = url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
// ignoring possible encoding issues
byte[] body = "param=value¶m2=value2".getBytes();
connection.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
connection.setRequestProperty("Content-length", String.valueOf(body.length));
// ignoring possible IOExceptions
OutputStream out = connection.getOutputStream();
out.write(body);
out.flush();
// use this to read back from server
InputStream in = connection.getInputStream();
正如你所看到的,这是很低级别的东西。这就是为什么你想使用库。
相关问题
- 1. HTML post to PHP
- 2. Jquery Post to external php
- 3. android multipart post to php
- 4. php post to use JSON_ENCODE
- 5. Java(Android)HTTP Post to PHP页面
- 6. jQuery AJAX post to php probleme
- 7. HTML form PHP post to email
- 8. php-How to post with ajax?
- 9. php curl post to pingdom not working
- 10. AJAX Post to self in PHP
- 11. PHP Post to Self with $ _FILES
- 12. POST to templateUrl
- 13. RedirectMatch example.com/post-slug to example.com/post/post-slug
- 14. javascript post to database
- 15. javascript to post to url and
- 16. $ .AJAX to $ .POST
- 17. post fla to youtube
- 18. Post File To Executable
- 19. Angular post to nodejs
- 20. PDF-To-HTML Post Action
- 21. POST image to webserver with java C++ python
- 22. 'post to Facebook'链接
- 23. how to send post to remote url and redirect to the url in php
- 24. 使用PHP POST POST CURL to JSON(使用Cookie.txt)
- 25. post to textfield using tcpdf
- 26. Angularjs Ajax Post to Epressjs
- 27. JQuery Ajax Post to C#
- 28. Post form to other controller
- 29. Android HTTPPost List <NameValuePair> post to php?
- 30. base64 image post to php results in empty file
您是指JavaScript还是来自Java Servlet? – amischiefr 2009-08-19 14:37:19
有很多是Java的东西,而不是Servelets。 – Quentin 2009-08-19 15:40:36