3

지금 잠시 동안 자바 스크립트를 압축 y를 응용 프로그램의 일부로 폐쇄를 사용하지만, 단지 봤는데 오류를 405 - Method not allowed구글 폐쇄 컴파일 REST API는 갑자기

내 코드 등을 받기 시작했다 "방법은 허용되지 않습니다"오류 405 예외 아래에서 몇 년 동안 일했지만, 지금은 멈췄다.

참고 : 이것은 내 애플리케이션의 자바 스크립트 파일에서 변경 사항이 감지 될 때 자주 호출되지 않습니다.

더 이상 폐쇄 정보 앱에서 오류 정보가 표시되지 않습니다.

분명히이 코드는 POST 작업을 수행합니다. 여기에있는 폼을 사용하면 https://closure-compiler.appspot.com/home이 작동하지만 브라우저가 URL에 연결되거나 코드를 사용하면 Error 405이됩니다. 내 코드가 GET 메서드를 시도하는 것처럼 거의 비슷하지만 ...

아이디어가 있으십니까?

Public Class Closure 

    Property OriginalCode As String 
    Property CompiledCode As String 
    Property Errors As ArrayList 
    Property Warnings As ArrayList 
    Property Statistics As Dictionary(Of String, Object) 

    Public Sub New(Input As String, Optional CompliationLevel As String = "SIMPLE_OPTIMIZATIONS") 

     Dim _HttpWebRequest As HttpWebRequest 
     Dim _Result As StringBuilder 
     Dim ClosureWebServiceURL As String = "http://closure-compiler.appspot.com/compile?" 
     Dim ClosureWebServicePOSTData As String = "output_format=json&output_info=compiled_code" & 
                     "&output_info=warnings" & 
                     "&output_info=errors" & 
                     "&output_info=statistics" & 
                     "&compilation_level=" & CompliationLevel & "" & 
                     "&warning_level=default" & 
                     "&js_code={0}" 


     '// Create the POST data 
     Dim Data = String.Format(ClosureWebServicePOSTData, HttpUtility.UrlEncode(Input)) 

     _Result = New StringBuilder 
     _HttpWebRequest = DirectCast(WebRequest.Create(ClosureWebServiceURL), HttpWebRequest) 
     _HttpWebRequest.Method = "POST" 
     _HttpWebRequest.ContentType = "application/x-www-form-urlencoded" 
     '//Set the content length to the length of the data. This might need to change if you're using characters that take more than 256 bytes 
     _HttpWebRequest.ContentLength = Data.Length 
     '//Write the request stream 
     Using SW As New StreamWriter(_HttpWebRequest.GetRequestStream()) 
      SW.Write(Data) 
     End Using 

     Try 

      Dim response As WebResponse = _HttpWebRequest.GetResponse() 

      Using responseStream As Stream = response.GetResponseStream 
       Dim encoding As Encoding = System.Text.Encoding.GetEncoding("utf-8") 
       Using readStream As New StreamReader(responseStream, encoding) 
        Dim read(256) As Char 
        Dim count As Integer = readStream.Read(read, 0, 256) 
        While count > 0 
         Dim str As New String(read, 0, count) 
         _Result.Append(str) 
         count = readStream.Read(read, 0, 256) 
        End While 
       End Using 
      End Using 

      Dim js As New JavaScriptSerializer 
      js.MaxJsonLength = Int32.MaxValue 

      Dim d As Dictionary(Of String, Object) = js.Deserialize(Of Dictionary(Of String, Object))(_Result.ToString()) 
      Me.CompiledCode = d.NullKey("compiledCode") 
      Me.Warnings = TryCast(d.NullKey("warnings"), ArrayList) 
      Me.Errors = TryCast(d.NullKey("errors"), ArrayList) 
      Me.Statistics = TryCast(d.NullKey("statistics"), Dictionary(Of String, Object)) 

     Catch ex As Exception 
      Me.CompiledCode = "" 
      If Me.Errors Is Nothing Then 
       Dim er As New List(Of String) 
       er.Add(ex.ToString()) 
       Me.Errors = New ArrayList(er) 
      Else 
       Me.Errors.Add(ex.ToString()) 
      End If 
     End Try 

     Me.OriginalCode = Input 

    End Sub 

End Class 

답변

3

폐쇄 REST API는 HTTPS로 리디렉션되고, 직접 리디렉션을 방지하기 위해 "https://closure-compiler.appspot.com/compile"에 게시하려고 할 수 있습니다.

+0

감사합니다. 너무 간단! 그게 지금 일하는 것 같습니다. 단지 실패하기 시작한 이유가 궁금합니다! –