2010-02-05 1 views
7

XML 데이터가 HTTP DELETE 요청의 본문에 포함되도록 요구하는 API와의 인터페이스를 시도하고 있습니다. AppEngine에서 urlfetch를 사용하고 있으며 페이로드가 단순히 DELETE 요청에 대해 무시됩니다.Google App Engine에서 DELETE 요청과 함께 본문 또는 페이로드를 보낼 수있는 방법이 있습니까?

Is an entity body allowed for an HTTP DELETE request?을 읽은 후, 표준에서 DELETE 요청시 본문 내용을 허용하지 않기 때문에 urlfetch가 본문을 스트립하는 이유입니다.

제 질문은 urlfetch가 페이로드를 무시할 때 app 엔진에서 본문 내용을 추가 할 수있는 일종의 해결 방법이 있습니까? , POST가, 머리, PUT 및 DELETE GET : the docs

답변

6

,

의 URL 가져 오기 서비스는 다섯 개 HTTP 방법을 지원합니다. 요청에는 HTTP 헤더와 POST PUT 요청의 본문 내용이 포함될 수 있습니다.

GAE Python 런타임이 많이 샌드 박스되면,이 제한을 피할 수 없을 것입니다. 버그라고 생각하고 아마도 here이라는 버그 리포트를 제출해야합니다.

+1

동의, 버그 같습니다. –

+0

나는이 문제에 별표를 표시하고 다음과 같이 논평했다. http://code.google.com/p/googleappengine/issues/detail?id=601&q=post%20delete&colspec=ID%20Type%20Status%20Priority%20Stars% 20Owner % 20Summary % 20Log % 20Component – elkelk

+0

elkelk, 그 버그는 여기의 질문과 관련이 없습니다. –

0

현재, 앱 엔진 소켓 API를 사용하여이 문제를 해결 얻을 수있는 그 이동의 모습입니다 :

client := http.Client{ 
     Transport: &http.Transport{ 
      Dial: func(network, addr string) (net.Conn, error) { 
       return socket.Dial(c, network, addr) 
      }, 
     }, 
    } 
2

당신의 HTTPRequest 확인하고 다른 않는 소켓을 통해 몸, 샘플 자바 코드와 DELETE 요청을 할 수 있습니다 본문과 함께 DELETE 요청 :

public static HTTPResponse execute(HTTPRequest request) throws ExecutionException, InterruptedException { 

    if (request == null) { 
     throw new IllegalArgumentException("Missing request!"); 
    } 

    if (request.getMethod() == HTTPMethod.DELETE && request.getPayload() != null && request.getPayload().length > 0) { 
     URL obj = request.getURL(); 
     SSLSocketFactory socketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault(); 
     try { 
      HttpsURLConnection con = (HttpsURLConnection) obj.openConnection(); 

      HttpsURLConnection.setDefaultSSLSocketFactory(socketFactory); 

      con.setRequestMethod("DELETE"); 
      for (HTTPHeader httpHeader : request.getHeaders()) { 
       con.setRequestProperty(httpHeader.getName(), httpHeader.getValue()); 
      } 
      con.setDoOutput(true); 
      con.setDoInput(true); 

      OutputStream out = con.getOutputStream(); 
      out.write(request.getPayload()); 
      out.flush(); 
      out.close(); 
      List<HTTPHeader> responseHeaders = new ArrayList<>(); 
      for (Map.Entry<String, List<String>> stringListEntry : con.getHeaderFields().entrySet()) { 
       for (String value : stringListEntry.getValue()) { 
        responseHeaders.add(new HTTPHeader(stringListEntry.getKey(), value)); 
       } 
      } 
      return new HTTPResponse(con.getResponseCode(), StreamUtils.getBytes(con.getInputStream()), con.getURL(), responseHeaders); 
     } catch (IOException e) { 
      log.severe(e.getMessage()); 
     } 
    } else { 
     Future<HTTPResponse> future = URLFetchServiceFactory.getURLFetchService().fetchAsync(request); 
     return future.get(); 
    } 
    return null; 
} 
관련 문제