Android istemcimden bir sunucuyu Multipart isteği olarak sunucuma gönderiyorum. Aşağıdaki isteği almak için bir sunucu tarafı yöntemi yazmam gerekiyor.Java: Multipart POST isteğinden video dosyası alın
BenKodum aşağıdaki gibidir sunucu tarafında Framework olarak Jersey kullanıyorum
- :
private void send_video_to_server(String videoPath) throws ParseException, IOException { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://MY_SERVER_URL/videos/postvideo"); FileBody filebodyVideo = new FileBody(new File(videoPath)); StringBody title = new StringBody(titleBox.getText().toString()); StringBody description = new StringBody(captionBox.getText().toString()); MultipartEntity reqEntity = new MultipartEntity(); reqEntity.addPart("videoFile", filebodyVideo); reqEntity.addPart("title", title); reqEntity.addPart("description", description); httppost.setEntity(reqEntity); // DEBUG System.out.println("executing request " + httppost.getRequestLine()); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); // DEBUG System.out.println(response.getStatusLine()); if (resEntity != null) { System.out.println(EntityUtils.toString(resEntity)); } // end if if (resEntity != null) { resEntity.consumeContent(); } // end if httpclient.getConnectionManager().shutdown(); }
Ben için SUNUCU yan kod yazmak istiyorum nasıl ALMAK Yukarıdaki istek? Yöntem İmzası, numaralı yanıt için yeterli olacaktır.
çok parçalı bir istek alır bir POST yöntemi olmamalı: Ayrıntılı Örneğin
, bahar öyle nasıl? – Dinuka
@Earthling Evet iyi HttpServlet, doGet yöntemine benzer şekilde geçersiz kılabileceğiniz doPost yöntemine de sahiptir. Bkz. [Link] (http://docs.oracle.com/javaee/7/api/javax/servlet/http/HttpServlet.html#doPost-javax.servlet.http.HttpServletRequest-javax.servlet.http.HttpServletResponse-) – taivo
Teşekkür ederim ama doPost'a ulaştığında bu istekleri dosyadan almak için hala kafam karıştı mı? Çok parçalı isteği nasıl kodlarım? – Dinuka