- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
可能这是一个重复的问题,但我已经尝试过该网站的所有答案,但都不起作用!
我正在使用 MultipartEntity
进行图像上传。它在模拟器中工作得很好,但是当我 checkin 设备时它不工作。
在我的代码下面
HttpParams params = new BasicHttpParams();
params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP);
HttpClient httpClient = new DefaultHttpClient(params);
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost("http://url.com/webservice_uploadvideo.php");
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.STRICT);
FileBody filebodyVideopre = new FileBody(new File(videoUploadpathPre)); //pre
entity.addPart("fin_detail", filebodyVideopre);
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost, localContext);
最佳答案
这是我的多部分图像上传的工作代码。是的,它可以在真实设备中使用。
private int uploadImage(String selectedImagePath) {
try {
HttpClient client = new DefaultHttpClient();
File file = new File(selectedImagePath);
HttpPost post = new HttpPost(Constants.URL);
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE,
Constants.BOUNDARY, Charset.defaultCharset());
entity.addPart(Constants.MULTIPART_FORM_DATA_NAME, new FileBody(file));
post.setHeader("Accept", "application/json");
post.setHeader("Content-Type", "multipart/form-data; boundary=" + Constants.BOUNDARY);
post.setEntity(entity);
HttpResponse response = client.execute(post);
HttpEntity httpEntity = response.getEntity();
int status = response.getStatusLine().getStatusCode();
return status;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
关于java - MultipartEntity 文件未通过设备上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36766819/
可能这是一个重复的问题,但我已经尝试过该网站的所有答案,但都不起作用! 我正在使用 MultipartEntity 进行图像上传。它在模拟器中工作得很好,但是当我 checkin 设备时它不工作。 在
所以我创建了一个 Workout 类,我想使用 HttpPost 将它发送到服务器。有什么方法可以将该类添加到 MultipartEntity 中,或者我应该如何发布它? 最佳答案 首先,您的类必须实
我想使用 MultipartEntity 上传图片。我尝试了以下代码。 我没有收到任何错误,但图片未上传。我有足够的上传权限 PHP 'success', 'm
在我开始之前,我看到了很多关于这个的问题,但对我来说没有任何用处也许有人可以向我解释或向我展示如何将位图压缩为 MultiPart 实体,然后使用 Retrofit 将其正确发送到服务器 最佳答案 对
不确定为什么会这样,但这行代码使我的应用程序在调试或运行模式下崩溃: MultipartEntity multipartEntity = new MultipartEntity(HttpMultipa
我最近将我的项目从 Eclipse 迁移到 Android Studio(我还没有完全控制这个 IDE)。在这个项目中,我有一个文件 uploader AsyncTask,它通过 http 发送多部分
文档说 org.apache.http.entity.mime.MultipartEntity类已弃用。有人可以给我推荐一个替代方案吗? 我在我的代码中这样使用它: entity.addPart("p
我想使用 MultipartEntity 上传单张图片。我尝试了以下代码。 但是图片没有上传。我没有收到任何错误。我已经为此添加了足够的库 try { HttpClient
这是我目前所拥有的: MultipartEntity reqEntity = new MultipartEntity(); String strXMLFilename = "/sdcard/image
我想使用 MultipartEntity 将图像和 JsonObject 发送到 PHP 服务器。这是我的代码: HttpClient httpClient = new DefaultHttpClie
我正在使用 MultiPartEntity 在我的 Android 应用程序中发布 XML + 图片,一切都很好,除了我要发布到的服务器要求我设置 Content- HTTP post 的类型到app
我在 MultipartEntity 中传递 3 张图像。这很好用,但我不知道如何将 String 值传递给 MultipartEntity。以下是我的代码: public void executeM
我一直在尝试将图像和数据上传到 Django 服务器。我包含了 apache-mime4j.0.6.jar 和 httpmime4.0.1.jar 库(Project->build path->Add
我想将文件的内容作为 org.apache.http.entity.mime.MultipartEntity 发送。问题是,我实际上没有文件,只有 String 形式的内容。以下测试完美运行,其中 f
如何执行此代码以便它在后台线程中发送? // TODO: Send image in background HttpClient httpclient = new Defaul
我需要将其解析为 JsonArray 而不是对象但它似乎无法正常工作。 my output is ["{"TransactionVolume":"34","TransactionitemID":"2"
我想在我的 AndroidHttpClient 中实现一个 ProgressDialog。我在这里找到了一个简单的实现 CountingMultipartEntity . 另外我添加了内容长度支持。我
我尝试在 Android 中使用 MultiPartEntity 和 HttpClient 发送图像,但不断收到异常:java.lang.UnsupportedOperationException:
我正在尝试使用 HttpClient 和 MultipartEntity 将图像从 Adroid 应用程序上传到 php 网络服务器。 这是我的代码 fragment : protected Void
我现在有一个 Tomcat 实例,它接受上传并对数据进行一些处理工作。 我想用符合类似 API 的新 servlet 替换它。首先,我希望这个新 servlet 将所有请求代理到旧的 servlet。
我是一名优秀的程序员,十分优秀!