Web请求代码无法运行

Web请求代码无法运行,web,request,Web,Request,在我的网页上单击按钮,我运行一个sql语句,我还想运行一个web请求。我不想从web请求加载任何内容,但请运行它。但有趣的是。作为sql语句的代码可以很好地运行jsut,而下面的所有代码似乎都无法运行。。。。完全服务器从未收到web请求 如果我将代码复制到一个页面,然后只运行web请求代码,它就会工作。但在这里,情况并非如此 asp.net。谢谢大家。我被难住了 Imports System Imports System.Data Imports System.Web Imports Syste

在我的网页上单击按钮,我运行一个sql语句,我还想运行一个web请求。我不想从web请求加载任何内容,但请运行它。但有趣的是。作为sql语句的代码可以很好地运行jsut,而下面的所有代码似乎都无法运行。。。。完全服务器从未收到web请求

如果我将代码复制到一个页面,然后只运行web请求代码,它就会工作。但在这里,情况并非如此

asp.net。谢谢大家。我被难住了

Imports System
Imports System.Data
Imports System.Web
Imports System.Data.SqlClient

Imports System.IO
Imports System.Net
Imports System.Text

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub btnAddDeckSize_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddDeckSize.Click
    If txtDeckSize.Text > "" And txtNewDeckPrice.Text > "" Then
        Dim WasError As Boolean = False
        Dim SQLstring As String = "Server=server;Database=SecondLifeDatabases;Integrated Security=true"
        Dim SQLconn As SqlConnection
        Dim SQLcmd As New SqlCommand()
        SQLconn = New SqlConnection(SQLstring)
        Try
            SQLconn.Open()
            SQLcmd.Connection = SQLconn
            Try
                SQLcmd.CommandText = ("INSERT INTO [SecondLifeDatabases].[dbo].[YuGiOh-DecksAndPrices]([DeckSize] ,[PriceInLindins])VALUES (" + txtDeckSize.Text + "," + txtNewDeckPrice.Text + ")")
                SQLcmd.ExecuteNonQuery()
            Catch ex As Exception
                Context.Response.Write("error:" + vbCrLf + " " + vbCrLf + "Unable to insert sql data, Type:" + vbCrLf + " " + vbCrLf + ex.Message)
                WasError = True
                SQLconn.Close()
            End Try
        Catch ex As Exception
            Context.Response.Write("error:" + vbCrLf + " " + vbCrLf + "Could not open database:" + vbCrLf + " " + vbCrLf + ex.Message)
            WasError = True
            SQLconn.Close()
        End Try
        SQLconn.Close()
        If WasError = False Then
            Context.Response.Redirect("~/YuGiOh.aspx")
        End If
    Else
        Context.Response.Write("Please check your values, something is Missing")
    End If
'代码似乎不运行的起始位置 '此代码单独在另一页上运行 但在这里,即使上面的代码运行, “我从来没有看到任何代码泄漏的结果

    ' Create a request using a URL that can receive a post. 
    Dim request As WebRequest = WebRequest.Create("http://sim6103.agni.lindenlab.com:12046/cap/b936c974-cfab-c2ee-a184-4288fe0a10f8")
    ' Set the Method property of the request to POST.
    request.Method = "POST"
    ' Create POST data and convert it to a byte array.
    Dim postData As String = "This is a test that posts this string to a Web server."
    Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
    ' Set the ContentType property of the WebRequest.
    request.ContentType = "application/x-www-form-urlencoded"
    ' Set the ContentLength property of the WebRequest.
    request.ContentLength = byteArray.Length
    ' Get the request stream.
    Dim dataStream As Stream = request.GetRequestStream()
    ' Write the data to the request stream.
    dataStream.Write(byteArray, 0, byteArray.Length)
    ' Close the Stream object.
    dataStream.Close()
    ' Get the response.
    Dim response As WebResponse = request.GetResponse()
    ' Display the status.
    Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
    ' Get the stream containing content returned by the server.
    dataStream = response.GetResponseStream()
    ' Open the stream using a StreamReader for easy access.
    Dim reader As New StreamReader(dataStream)
    ' Read the content.
    Dim responseFromServer As String = reader.ReadToEnd()
    ' Display the content.
    Console.WriteLine(responseFromServer)
    ' Clean up the streams.
    reader.Close()
    dataStream.Close()
    response.Close()
End Sub