gpt4 book ai didi

post - Google Closure 编译 REST Api 突然抛出 Error 405 "Method not allowed"

转载 作者:行者123 更新时间:2023-12-04 18:40:26 25 4
gpt4 key购买 nike

一段时间以来,我一直在使用 Closure 作为 y 应用程序的一部分来压缩 Javascript,但刚开始出现错误 405 - Method not allowed

我下面的代码运行了几年,但现在已经停止了。

注意:这并不经常调用,只是在我的应用程序的 Javascript 文件中检测到任何更改时才调用。

除此之外,我从 Closure 应用程序中没有得到更多的错误信息。

显然这段代码执行了一个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

最佳答案

关闭 REST api 正在重定向到 https,您可能想尝试直接 POST 到“https://closure-compiler.appspot.com/compile”以避免重定向。

关于post - Google Closure 编译 REST Api 突然抛出 Error 405 "Method not allowed",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47206109/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com