2012-05-31 2 views
0

승인을 통해 Amazon S3 버킷에 파일을 업로드하려고합니다. 내 서명 작업을 알고 있습니다. 동일한 URL, 헤더 및 서명을 hurl.it과 함께 사용하면 업로드가 성공적으로 완료됩니다.HTTP 응답 S3에 업로드시 엔티티가 비어 있지는 않지만 실제로 작동합니다.

또한 내 프로그램이 정상적으로 업로드된다는 것을 알고 있습니다. S3 보안을 해제하고 헤더를 제거하면 업로드가 정상적으로 작동합니다.

HttpClient client = new DefaultHttpClient(); 
url = "http://mybucket.s3.amazonaws.com/test/" + filename; 

HttpPut put = new HttpPut(url); 
put.setEntity(entity); 
put.addHeader("Date", formattedDate); 
put.addHeader("Authorization", 
       "AWS " + c.getString(R.string.AWSAccessKeyId) + 
       ":" + signature); 
put.addHeader("Content-Type",contentType); 


HttpResponse httpResponse = client.execute(put); 
Log.e(TAG, allHeaders(httpResponse)); 

HttpEntity responseEntity = httpResponse.getEntity(); 
InputStream content = responseEntity.getContent(); 
InputStreamReader is = new InputStreamReader(content); 
BufferedReader br = new BufferedReader(is,2000); 

String read = br.readLine(); 
Log.e("AUTH", ">>>"+read+"<<<"); 
String response = ""; 
while (read != null){ 
    Log.e("AUTH", read); 
    read = br.readLine(); 
    response += read + "\n"; 
} 

Log.e("Code:", ""+httpResponse.getStatusLine().getStatusCode()); 

또한 내가 비동기 안드로이드 에뮬레이터에서이 일을 해요 있음을 주목할 필요가있다.

Date: Thu, 31 May 2012 05:58:08 GMT 
Connection: close 
Server: AmazonS3 
Transfer-Encoding: chunked 

응답 상태 코드 400: Bad Request이다

얻어진 헤더

은 ( Log.e(TAG, allHeaders(httpResponse))을 사용하여 표시).

이상한 점은이 헤더를 얻을 수 있지만 responseEntity.getContent()의 콘텐츠 스트림이 완전히 비어 있습니다. while 루프를 입력하지 않습니다.

www.google.com으로 타겟팅 된 HttpGet으로 전환하려고 시도했지만 완전히 정상적으로 작동했습니다.

청크 인코딩에 문제가 있습니까? 명백한 실수는 없습니까?

답변

0

나는 왜 이것이 효과가 있었는지 모르겠지만 어떻게 든 내 서명 인코딩은 전체 http 모델을 완전히 망쳐 놓은 숨겨진 캐릭터를 추가하고있었습니다. 방금 마지막 문자없이 서명의 하위 문자열을 사용했고 청크 분할 스트림을 읽을 수있었습니다.