Tag: multipartentity

在Android中使用MultipartEntityBuilder时,HttpPost返回错误

我正在尝试查询“ http://www.idmypill.com/api/id/”api ,我收到的JSON字符串是{“results”:[],”success”:false,”errors”:null}这是我的服务处理程序类: public String makeServiceCall(String url, int method, String api, byte[] pillImage) { try { // http client DefaultHttpClient httpClient = new DefaultHttpClient(); HttpEntity httpEntity = null; HttpResponse httpResponse = null; // Checking http request method type if (method == POST) { android.os.Debug.waitForDebugger(); HttpPost httpPost = new HttpPost(url); httpPost.setHeader(“data = api_key”, api); MultipartEntityBuilder builder […]

Android HttpClient Post File MultipartEntity

我正在尝试使用HttpClient和MultipartEntity将图像从Adroid应用程序上传到php webserver。 这是我的代码片段: protected Void doInBackground(Void… params) { HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); HttpPost post = new HttpPost( “http://URL/upload.php” ); try { MultipartEntity entity = new MultipartEntity( ); entity.addPart(“type”, new StringBody(“photo”)); entity.addPart(“data”, new FileBody(new File (this.path))); post.setEntity(entity); post.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); post.addHeader( “Content-Type”, “multipart/form-data; “); HttpResponse response = client.execute(post); HttpEntity resEntity = response.getEntity(); System.out.println(response.getStatusLine()); client.getConnectionManager().shutdown(); […]

通过HTTP POST上传文件

我想使用HTTP POST将文件(特定于图像)上传到REST服务器。 我已经导入/添加到构建路径httpmime-4.3.1.jar和apache-mime4j-0.6.jar 。 我在堆栈跟踪中得到以下错误。 这有效吗? post.setHeader(“enctype”, “multipart/form-data”); HTTP POST代码 public void multiPartPost() throws ClientProtocolException, IOException { File image = new File(EXTERNALSTORAGE + “/Pictures/sample.jpg”); FileBody fileBody = new FileBody(image); HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); post.setHeader(“enctype”, “multipart/form-data”); MultipartEntityBuilder multipartEntity = MultipartEntityBuilder.create(); multipartEntity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); multipartEntity.addPart(“sampleImage”, fileBody); post.setEntity(multipartEntity.build()); HttpResponse response = client.execute(post); String responseBody […]

HTTP multipart和chunking可以共存吗?

我正在使用apache HttpClient将几个文件发布到服务器。 这是代码: public static HttpResponse stringResponsePost(String urlString, String content, byte[] image, HttpContext localContext, HttpClient httpclient) throws Exception { URL url = new URL(URLDecoder.decode(urlString, “utf-8”)); URI u = url.toURI(); HttpPost post = new HttpPost(); post.setURI(u); MultipartEntity reqEntity = new MultipartEntity(); StringBody sb = new StringBody(content, HTTP_CONTENT_TYPE_JSON, Charset.forName(“UTF-8”)); ByteArrayBody ib = new ByteArrayBody(image, HTTP_CONTENT_TYPE_JPEG, “image”); reqEntity.addPart(“interview_data”, […]