内部服务器错误 (500) httpwebrequest

Posted

技术标签:

【中文标题】内部服务器错误 (500) httpwebrequest【英文标题】:Internal server error (500) httpwebrequest 【发布时间】:2010-11-20 15:45:50 【问题描述】:

System.Net.WebException:远程 服务器返回错误:(500) 内部服务器错误。在 System.Net.HttpWebRequest.GetResponse() 在 refill.btnRequestRefill_Click(对象 发件人,EventArgs e)

我在尝试提交表单时收到此错误。这是我的代码:

Protected Sub btnRequestRefill_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRequestRefill.Click

    Try
        Dim url As String = "www.domainname.com"

        url += "lastName=" & LastName.Text
        url += "&birthDate=" & Birthdate.Text
        url += "&RxNumbers=" & RxNumber.Text
        url += "&deliveryMethod=" & deliverymethod.SelectedValue
        url += "&phone=" & PhoneNumber.Text
        url += "&email=" & Email.Text

        Dim myrequest As HttpWebRequest = TryCast(WebRequest.Create(url), HttpWebRequest)

        Dim docresponse As WebResponse = myrequest.GetResponse()
        Dim responsestream As Stream = docresponse.GetResponseStream()
        Dim objXMLDoc As New XmlDocument()
        Dim colElements As XmlNodeList
        Dim colElements2 As XmlNodeList
        Dim mywebclient As New WebClient()
        Dim a As Object
        Dim listingscount As Integer = 0

        objXMLDoc.Load(responsestream)
        colElements = objXMLDoc.GetElementsByTagName("script")

        For Each objnode As XmlNode In colElements
            Dim attCol As XmlAttributeCollection = objnode.Attributes

            If objnode.Name = "script" Then
                If attCol(0).Value = "false" Then
                    colElements2 = objXMLDoc.GetElementsByTagName("rxResponse")
                    For Each objnode2 As XmlNode In colElements2
                        Response.Write("<br/>" & objnode2.InnerText & "<br/>")
                    Next
                Else
                    Response.Write("<br/>yay it when through<br/>")

                    Dim redir, mailto, mailfrom, subject, item, body, cc, bcc, message, html, template, usetemplate, testmode
                    subject = "Refill Submit - test"

                    usetemplate = False

                    Dim msg = Server.CreateObject("CDO.Message")
                    msg.subject = subject
                    msg.to = "name@domainname.com,name@domainname.com,name@domainname.com"
                    msg.from = "name@domainname.com"

                    For Each item In Request.Form
                        Select Case item
                            Case "redirect", "mailto", "cc", "bcc", "subject", "message", "template", "html", "testmode", "__EVENTTARGET", "__EVENTARGUMENT", "__VIEWSTATE", "__EVENTVALIDATION", "btnRequestRefill","__LASTFOCUS"
                            Case Else
                                If Not usetemplate Then
                                    If item <> "mailfrom" Then body = body & item & ": " & Request.Form(item) & vbCrLf & vbCrLf
                                Else
                                    body = Replace(body, "[$" & item & "$]", Replace(Request.Form(item), vbCrLf, "<br>"))
                                End If
                        End Select
                    Next

                    If usetemplate Then 'remove any leftover placeholders
                        Dim rx As New Regex("\[\$.*\$\]")
                        body = rx.Replace(body, "")
                    End If

                    If usetemplate And LCase(Request.Form("html")) = "yes" Then
                        msg.htmlbody = body
                    Else
                        msg.textbody = body
                    End If

                    msg.send()
                    msg = Nothing
                End If
            Else
                Response.Write("<br/>" & "not script" & "<br/>")
            End If
            'Response.Write("<br/>" & objnode.Name & ": " & objnode.InnerText & "<br/>")
        Next
    Catch ex As Exception
        Response.Write("<br/>" & ex.ToString & "<br/>")

    End Try
End Su

【问题讨论】:

您有什么方法可以获取远程服务器错误的详细信息吗?您确定要获取的 URL 有效吗?从您的示例来看,您似乎没有提供有效的 URL。 出于对客户保密的原因,我不得不更改网址 【参考方案1】:

我只是想说明我正在从另一个开发人员那里接管这段代码。我从该公司发现,这是之前假设的,实际上缺少服务所需的查询字符串。只需添加 url +="querystring=" & value 它就可以了。

【讨论】:

以上是关于内部服务器错误 (500) httpwebrequest的主要内容,如果未能解决你的问题,请参考以下文章

500内部服务器错误是啥意思?

HTTP 500内部服务器错误怎么解决。

HTTP 错误 500.100 - 内部服务器错误 - ASP 错误

内部服务器错误 (500) httpwebrequest

部署网站:500 - 内部服务器错误

出现意外错误类型 = 内部服务器错误,状态 = 500