本文介绍了上传图片从Android的PHP服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要上传图片到预计HTTPPOST以下参数远程PHP服务器:

I need to upload an image to a remote PHP server which expects the following parameters in HTTPPOST:

*$_POST['title']*
*$_POST['caption']*
*$_FILES['fileatt']*

大多数互联网搜索的建议之一:

Most of the internet searches suggested either :

下载下面的类,并试图MultiPartEntity发送请求:

apache-mime4j-0.5.jar
httpclient-4.0-beta2.jar
httpcore-4.0-beta3.jar
httpmime-4.0-beta2.jar

使用的URLConnection并处理多部分数据的自己。

顺便说一句,我很热衷于使用的HttpClient类,而不是java.net(或者是android.net)班。最后,我下载了多节类从Android源$ C ​​$ C,并利用它们在我的项目,而不是。

Btw, I am keen on using HttpClient class rather than java.net(or is it android.net) classes. Eventually, I downloaded the Multipart classes from the Android source code and used them in my project instead.

虽然这可以通过任何上述的方法来完成,我想确保,如果这些都实现上述目标的唯一途径。我脱脂通过文档,发现一个 FileEntity 类,但我无法得到它的工作。

Though this can be done by any of the above mentioned methods, I'd like to make sure if these are the only ways to achieve the said objective. I skimmed through the documentation and found a FileEntity class but I could not get it to work.

什么是正确的方式来得到这个Android应用程序做了什么?

What is the correct way to get this done in an Android application?

感谢。

推荐答案

在Android源仿佛带了一个内部​​多部分助手库。 看到这个帖子。在快速浏览,这比大量的公共的API更好地记录(咳咳,的Soundpool,咳),所以应该只使用一个插入式解决方案一个pretty的良好的开端,或者可能罚款。

The Android source seems to come with an internal multipart helper library. See this post. At a quick glance, it's better documented than plenty of public APIs (cough cough, SoundPool, cough cough), so it should be a pretty good place to start, or possibly fine to just use a drop-in solution.

这篇关于上传图片从Android的PHP服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 05:49