0
下面的代碼工作的一些網址,但有參數的一些其他URL返回錯誤:The remote server returned an error: (405) Method Not Allowed.
VB.NET遠程服務器返回錯誤:(405)方法不允許
我的工作:
Dim objHttpWebRequest As HttpWebRequest = Nothing
Dim objHttpWebResponse As HttpWebResponse = Nothing
Dim objRequestStream As Stream = Nothing
Dim objResponseStream As Stream = Nothing
Dim objXMLReader As XmlTextReader
Try
objHttpWebRequest = WebRequest.Create(URL)
'Start HttpRequest
objHttpWebRequest.Method = "POST"
objHttpWebRequest.ContentType = "application/xml"
'Get Stream Object
objRequestStream = objHttpWebRequest.GetRequestStream()
objRequestStream.Close()
'Start HTTP Response
objHttpWebResponse = objHttpWebRequest.GetResponse()
If objHttpWebResponse.StatusCode = HttpStatusCode.OK Then
objResponseStream = objHttpWebResponse.GetResponseStream()
objXMLReader = New XmlTextReader(objResponseStream)
Dim xmldoc As XmlDocument = New XmlDocument
xmldoc.Load(objXMLReader)
XMLResponse = xmldoc
objXMLReader.Close()
End If
問題在我使用的方法中?或內容類型?
謝謝@Markus,當我改變了方法「GET」,它返回的異常: 調用時 「不能與這個動詞型發送的內容體」方法GetRequestStream() –
@Samer_Azar在GET請求中,你不包含一個主體。您不需要設置內容類型,也可以避免訪問請求流。 – Markus