2014-11-04 6 views
0

Java에서 호출을 중단하는 매개 변수 또는 추가 회선 코드를 어떻게 추가합니까? 설정 방법에 GET/Objectname 퍼팅Jav 나머지 호출 매개 변수를 사용하여 호출

GET /ObjectName HTTP/1.1 
Host: BucketName.s3.amazonaws.com 
Date: date Authorization: authorization string (see Authenticating Requests (AWS Signature Version 
4)) Range:bytes=byte_range 

오류를 야기한다.

내가 사용하는 코드는 다음과 같습니다.

public void getObject() throws Exception 
{ 
String fmt = "EEE, dd MMM yyyy HH:mm:ss "; 

SimpleDateFormat df = new SimpleDateFormat(fmt, Locale.US); 
df.setTimeZone(TimeZone.getTimeZone("GMT")); 
String ob2 = "/bucket/test.txt"; 
String bucket = "/bucket"; 
String method = "GET"; 
String contentMD5 = ""; 
String contentType = ""; 
String date = df.format(new Date()) + "GMT";   

// Generate signature 
StringBuffer buf = new StringBuffer(); 
buf.append(method).append("\n");`enter code here` 
buf.append(contentMD5).append("\n"); 
buf.append(contentType).append("\n"); 
buf.append(date).append("\n"); 
buf.append(ob2); 
String signature = sign(buf.toString()); 

HttpURLConnection httpConn = null; 
URL url = new URL("https”,”s3demo.s3demosite.com",443,bucket); 
httpConn = (HttpURLConnection) url.openConnection(); 
httpConn.setDoInput(true); 
httpConn.setDoOutput(true); 
httpConn.setUseCaches(false); 
httpConn.setDefaultUseCaches(false); 
httpConn.setAllowUserInteraction(true); 
httpConn.setRequestMethod(method); 
httpConn.setRequestProperty("Date", date); 
httpConn.setRequestProperty("Content-Length", "0"); 
String AWSAuth = "AWS " + keyId + ":" + signature; 
httpConn.setRequestProperty("Authorization", AWSAuth); 

// Send the HTTP PUT request. 
int statusCode = httpConn.getResponseCode(); 
InputStream err = httpConn.getErrorStream(); 
InputStream is = null; 
is = httpConn.getInputStream(); 
int ch; 
StringBuffer sb = new StringBuffer(); 
while ((ch = err.read()) != -1) { 
    sb.append((char) ch); 
} 
if ((statusCode/100) != 2) 
{ 
    // Deal with S3 error stream. 
    InputStream in = httpConn.getErrorStream(); 
    System.out.println("Error: "+errorStr); 
} 
else 
{ 
    System.out.println("download worked”); 
} 
} 
+1

지금까지 사용중인 코드를 표시 할 수 있습니까? –

+0

서비스를 중지하는 매개 변수를 전달 하시겠습니까? – dnsserver

답변

0

REST 서비스에서는 두 가지 방법으로 매개 변수를 전달할 수 있습니다. 경로 변수 쿼리 인수로

  • 같은

    1. . 예 : GET /students/tom 또는 GET /students?name=tom
  • +0

    답변에 Java 코드가 표시되지 않습니다. –

    +0

    예. 그냥 매개 변수를 REST 서비스에 전달하는 두 가지 방법이 있다는 것을 설명합니다. – dnsserver

    +0

    추가 된 코드가 보이면 httpConn.setRequestMethod (method); GET POST 만 허용합니다. 경로 변수를 추가하면 프로그램 오류가 발생합니다. –

    관련 문제