无法通过https从VB.Net WebRequest向CakePHP 3应用程序发布数据

无法通过https从VB.Net WebRequest向CakePHP 3应用程序发布数据,vb.net,cakephp,https,cakephp-3.0,webrequest,Vb.net,Cakephp,Https,Cakephp 3.0,Webrequest,我们可以通过https将数据从VB.Net发布到CakePHP吗?使用下面的代码,它只显示“GET”而不是“POST”响应,所以如果使用$this->request->getData(),将返回空数组 注: post在http上的CakePHP3上工作,或在https上的本机php上工作 使用VB.NET2008,目标框架:3.5 使用CakePHP3.5.3 Wamp服务器3.1.0 64位 Apache2.4.27-PHP5.6.31 VB.Net应用程序代码: 'ByPass SSL

我们可以通过https将数据从VB.Net发布到CakePHP吗?使用下面的代码,它只显示“GET”而不是“POST”响应,所以如果使用$this->request->getData(),将返回空数组

注:

  • post在http上的CakePHP3上工作,或在https上的本机php上工作
  • 使用VB.NET2008,目标框架:3.5
  • 使用CakePHP3.5.3
  • Wamp服务器3.1.0 64位
  • Apache2.4.27-PHP5.6.31

VB.Net应用程序代码:

'ByPass SSL Certificate Validation Checking
    System.Net.ServicePointManager.ServerCertificateValidationCallback = _
      Function(se As Object, _
      cert As System.Security.Cryptography.X509Certificates.X509Certificate, _
      chain As System.Security.Cryptography.X509Certificates.X509Chain, _
      sslerror As System.Net.Security.SslPolicyErrors) True

    'Call web application/web service with HTTPS URL
    Dim request As WebRequest = WebRequest.Create("https://localhost/testapp/test/")

    ' 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 = "name=yos"
    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()

    txtResponse.Text = responseFromServer

    'Restore SSL Certificate Validation Checking
    System.Net.ServicePointManager.ServerCertificateValidationCallback = Nothing

CakePHP代码:

'ByPass SSL Certificate Validation Checking
    System.Net.ServicePointManager.ServerCertificateValidationCallback = _
      Function(se As Object, _
      cert As System.Security.Cryptography.X509Certificates.X509Certificate, _
      chain As System.Security.Cryptography.X509Certificates.X509Chain, _
      sslerror As System.Net.Security.SslPolicyErrors) True

    'Call web application/web service with HTTPS URL
    Dim request As WebRequest = WebRequest.Create("https://localhost/testapp/test/")

    ' 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 = "name=yos"
    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()

    txtResponse.Text = responseFromServer

    'Restore SSL Certificate Validation Checking
    System.Net.ServicePointManager.ServerCertificateValidationCallback = Nothing
TestController.php

AppController.php


服务器响应

GET //should be POST
Array() //should be Array([name] => yos)
GET //should be POST
Array() //should be Array([name] => yos)