迁移到新服务器后无法读取Request.form()值

时间:2018-12-01 11:49:50

标签: asp.net asp.net-web-api handhelddevice

我有一个Web API。我正在从我的Android应用程序,Windows应用程序以及Fibocom G510手持终端设备调用此API。一切正常,直到更换服务器。服务器迁移后,我没有得到结果。这是调用API的vb.net Windows应用程序代码。

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim iRemoteUrl As String
    Dim iDataPart As String
    Dim iEncoding As ASCIIEncoding = New ASCIIEncoding

    Dim iData As String

    Dim iBytes() As Byte
    Dim iHttpRequest As HttpWebRequest
    Dim iStream As IO.Stream
    Dim iResponse As WebResponse
    Dim iReader As StreamReader
    Dim iResponseFromServer As String

    Try
        iRemoteUrl = "http://demo.bmatestore.com/TAPI/Test.aspx"
        iDataPart = "hadcaaz.asz|mambbkmrmaumjmamrvmwmbsmrkmcmwqmxnmkmzmmlmbmmmpmamwmbhcz|tashz|arasiarauz|tasz|astz|aaz|aswz|msfmambmeysmfz~aaaraxaaaraxz~auasasdgmkasasaxaayodlasjaslarauksgasasasyaskj"
        iData = String.Format("DataPart={0}", iDataPart)
        iBytes = iEncoding.GetBytes(iData)

        iHttpRequest = CType(WebRequest.Create(iRemoteUrl), HttpWebRequest)

        iHttpRequest.Method = "POST"
        iHttpRequest.ContentType = "application/x-www-form-urlencoded"
        iHttpRequest.ContentLength = iBytes.Length()
        iStream = iHttpRequest.GetRequestStream
        iStream.Write(iBytes, 0, iBytes.Length)
        iStream.Close()

        iResponse = iHttpRequest.GetResponse()
        iStream = iResponse.GetResponseStream()
        iReader = New StreamReader(iStream)
        iResponseFromServer = iReader.ReadToEnd()

        MsgBox(iResponseFromServer)

        iReader.Close()
        iStream.Close()
        iResponse.Close()
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub

在我的WebAPI中,我有以下代码。

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me. Load
    Dim iData As String
    Dim iResult As String

    Try
        iData = Request.Form("DataPart")
        If iData = "" Then
            iResult = "<message>0|0|0|2|Input data is not given</message>"
        Else
            iResult = ProcessTerminalAPI(iData, Server.MapPath("~/"), "Page")
        End If

        Response.Write(iResult)
    Catch ex As Exception
    End Try
End Sub

我总是

<message>0|0|0|2|Input data is not given</message> 

作为响应。我还发现,如果我将iRemoteUrl从 https://jsfiddle.net/ar5dbn30/16/http://demo.bmatestore.com/TAPI/Test.aspx可以正常工作。但是我希望这也可以在HTTP中工作。这是因为如前所述,fibocom G510手持终端将使用此API,当在其代码中使用HTTPS时,该终端将无法连接。使用HTTP时它可以连接,但不幸的是没有得到正确的结果。如果有人遇到这种情况,请提供帮助。

0 个答案:

没有答案