http 클라이언트를 사용하여 JSON으로 파일을 보내고 싶습니다. 어떻게 시작해야할지 모르겠습니다. 누구든지해야 할 일을 제안 할 수 있습니까? 이 JSON 형식으로 데이터를 보내겠습니다.
{
"Filename": "282850ad-de5c-498f-8280-2d4b6d77b774.jpg",
"ChunkId":1,
"ChunkLength":11397,
"FileLength":11397
}
보시다시피 파일을 청크로 보내겠습니다. 파일을 바이트 배열로 변환 할 것인지 모르겠습니다. 필요한 경우 누구나 샘플 코드 감사를 드릴 수 있습니다.
서버에서 텍스트 파일 또는 이미지 파일을 보내려면 MultiPartEntity를 사용할 수 있습니다.
DefaultHttpClient localDefaultHttpClient = new DefaultHttpClient();
FileBody localFileBody = new FileBody(new File(this.picturePath), "image/jpg");
HttpPost localHttpPost = new HttpPost("http://website.com/path/....");
MultipartEntity localMultipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
try
{
Log.d("picturepath", this.picturePath);
localMultipartEntity.addPart("Email", new StringBody("[email protected]"));
localMultipartEntity.addPart("password", new StringBody("password"));
localMultipartEntity.addPart("phone", new StringBody("9875......."));
localMultipartEntity.addPart("profilepicture", localFileBody);
localHttpPost.setEntity(localMultipartEntity);
HttpResponse localHttpResponse = localDefaultHttpClient.execute(localHttpPost);
System.out.println("responsecode" + localHttpResponse.getStatusLine().getStatusCode());
}
catch (Exception e)
{
Log.d("exception", e.toString());
}
이 코드는 내 Running 프로젝트의 일부이므로 작동합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다