内部服务器错误(500)httpwebrequest

时间:2010-11-20 15:45:50

标签: httpwebrequest system.net.webexception

  

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

1 个答案:

答案 0 :(得分:0)

我只是想记下我是从另一个开发人员手中接过这个代码的。我从公司发现,在此之前,假设该服务实际上缺少一个查询字符串。只需添加url + =“querystring =”&amp;这是有效的。