2014-11-29 1 views

답변

0

사용 HTTP POST 요청 ... 바이트 배열로 이미지를 변환 한 후 서버로 전송

InputStream is = this.getAssets().open("image.png"); 
HttpClient httpClient = new DefaultHttpClient(); 
HttpPost postRequest = 
new HttpPost("http://webserver.com/doSomething.do"); 
byte[] data = IOUtils.toByteArray(is); 
InputStreamBody isb = new InputStreamBody(new 
ByteArrayInputStream(data), "uploadedFile"); 
StringBody sb1 = new StringBody("some text goes here"); 
StringBody sb2 = new StringBody("some text goes here too"); 
MultipartEntity multipartContent = new MultipartEntity(); 
multipartContent.addPart("uploadedFile", isb); 
multipartContent.addPart("one", sb1); 
multipartContent.addPart("two", sb2); 
postRequest.setEntity(multipartContent); 
HttpResponse response =httpClient.execute(postRequest); 
response.getEntity().getContent().close(); 
0

당신은이이

String _URL =https://194.1.3.9:7721/request?image_byte=iamge _inbyte; 
HttpClient client = getHttpClient(); 
HttpPost request = new HttpPost(_URL); 
HttpResponse response = client.execute(request); 

    private static HttpClient getHttpClient() { 
     if (mHttpClient == null) { 
      mHttpClient = new DefaultHttpClient(); 
      final HttpParams params = mHttpClient.getParams(); 
      HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT); 
      HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT); 
      ConnManagerParams.setTimeout(params, HTTP_TIMEOUT); 
     } 
     return mHttpClient;  
    } 
+0

URL에 바이트를 넣고 빈 게시물을 작성하는 것은 매우 재미 있습니다. 정말로 우스운 이야기. – greenapps

관련 문제