/** 构造HttpPut */ protected HttpUriRequest generateHttpRequest() { // 生成Http请求 String resource = httpTool.generateCanonicalizedResource( "/" + objectGroup.getBucketName() + "/" + objectGroup.getName()); String requestUri = OSS_END_POINT + resource; HttpPut httpPut = new HttpPut(requestUri); // 构造HttpPut String authorization = OSSHttpTool.generateAuthorization( accessId, accessKey, httpMethod.toString(), "", objectGroupMetaData.getContentType(), Helper.getGMTDate(), OSSHttpTool.generateCanonicalizedHeader(objectGroupMetaData.getAttrs()), resource); httpPut.setHeader(AUTHORIZATION, authorization); httpPut.setHeader(DATE, Helper.getGMTDate()); httpPut.setHeader(HOST, OSS_HOST); try { httpPut.setEntity(new StringEntity(generateHttpEntity())); } catch (UnsupportedEncodingException e) { // Log.e(this.getClass().getName(), e.getMessage()); } return httpPut; }
/* * (non-Javadoc) * @see * com.aliyun.android.oss.task.Task#generateHttpRequest() */ @Override protected HttpUriRequest generateHttpRequest() { // 生成Http请求 String resource = httpTool.generateCanonicalizedResource("/" + bucketName); String requestUri = OSS_END_POINT + resource; requestUri = OSSHttpTool.appendParameterPair(requestUri, PREFIX, prefix); requestUri = OSSHttpTool.appendParameterPair(requestUri, MARKER, marker); if (maxKeys != null && maxKeys != DEFAULT_MAX_KEYS) { requestUri = OSSHttpTool.appendParameterPair(requestUri, MAX_KEYS, maxKeys.toString()); } requestUri = OSSHttpTool.appendParameterPair(requestUri, DELIMITER, delimiter); // Log.d("requestUri", requestUri); HttpGet httpGet = new HttpGet(requestUri); // 构造HttpGet String dateStr = Helper.getGMTDate(); String content = "GET\n\n\n" + dateStr + "\n" + resource; String authorization = OSSHttpTool.generateAuthorization(accessId, accessKey, content); httpGet.setHeader("Authorization", authorization); httpGet.setHeader("Date", dateStr); httpGet.setHeader("Host", OSS_HOST); return httpGet; }
/** 构造HttpPut */ protected HttpUriRequest generateHttpRequest() { // 生成Http请求 String resource = httpTool.generateCanonicalizedResource("/" + bucketName + "/" + objectKey); String requestUri = OSS_END_POINT + resource; HttpPut httpPut = new HttpPut(requestUri); // 构造HttpPut String dateStr = Helper.getGMTDate(); String xossHeader = OSSHttpTool.generateCanonicalizedHeader(objectMetaData.getAttrs()); String authorization = OSSHttpTool.generateAuthorization( accessId, accessKey, httpMethod.toString(), "", objectMetaData.getContentType(), dateStr, xossHeader, resource); httpPut.setHeader(AUTHORIZATION, authorization); httpPut.setHeader(DATE, dateStr); httpPut.setHeader(HOST, OSS_HOST); OSSHttpTool.addHttpRequestHeader(httpPut, CACHE_CONTROL, objectMetaData.getCacheControl()); OSSHttpTool.addHttpRequestHeader( httpPut, CONTENT_DISPOSITION, objectMetaData.getContentDisposition()); OSSHttpTool.addHttpRequestHeader( httpPut, CONTENT_ENCODING, objectMetaData.getContentEncoding()); OSSHttpTool.addHttpRequestHeader(httpPut, CONTENT_TYPE, objectMetaData.getContentType()); OSSHttpTool.addHttpRequestHeader( httpPut, EXPIRES, Helper.getGMTDate(objectMetaData.getExpirationTime())); // 加入用户自定义header for (Entry<String, String> entry : objectMetaData.getAttrs().entrySet()) { OSSHttpTool.addHttpRequestHeader(httpPut, entry.getKey(), entry.getValue()); } if (this.data != null && this.data.length > 0) { httpPut.setEntity(new ByteArrayEntity(this.data)); } return httpPut; }