2010-11-20 77 views
1

System.Net.WebException: The remote server returned an error: (500) Internal Server Error. at System.Net.HttpWebRequest.GetResponse() at refill.btnRequestRefill_Click(Object sender, EventArgs e)內部服務器錯誤(500)httpwebrequest

嘗試提交表單時出現此錯誤。這裏是我的代碼:

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 = "[email protected],[email protected],[email protected]" 
        msg.from = "[email protected]" 

        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 
+0

你有什麼辦法可以獲得遠程服務器錯誤的詳細信息嗎?你確定你試圖得到的URL是有效的嗎?從你的例子看來,你似乎並沒有提供一個有效的URL。 – Oded 2010-11-20 15:49:59

+0

我不得不因爲保密原因更改網址給客戶 – 2010-11-20 16:01:11

回答

0

我只是想說明我是從另一個開發人員接管這段代碼。我從公司發現,這是假設之前實際上有一個服務所需的缺少查詢字符串。通過添加url + =「querystring =」&它的工作價值。