Home > Net >  The POST request under the HTTPS
The POST request under the HTTPS

Time:03-07

My original works under the HTTP application can't run in the HTTPS now, who have the ready-made code reference,

CodePudding user response:

Is to send a generation of password request received a reply

CodePudding user response:

 Private Function getPageBytes (ByVal url As [String], ByVal paramList As NameValueCollection, ByVal wideCharEncoding the As System. Text. The Encoding, ByVal method As String, ByVal resetCookie As Boolean) As Byte () 
Dim res As HttpWebResponse=Nothing
Dim the result As the New System. Collections. ArrayList (5000)

Try
Dim the req As HttpWebRequest=Nothing
'if it is send HTTPS requests
If the url. StartsWith (" HTTPS, "StringComparison. OrdinalIgnoreCase) Then
ServicePointManager. ServerCertificateValidationCallback=New RemoteCertificateValidationCallback (AddressOf CheckValidationResult)
ServicePointManager. SecurityProtocol=CType (& amp; HC0 Or & amp; H300 Or & amp; HC00 SecurityProtocolType)
The req=TryCast (WebRequest. Create (url), HttpWebRequest)
The req. ProtocolVersion=HttpVersion. Version10
The Else
The req=TryCast (WebRequest. Create (url), HttpWebRequest)
End the If
The req. AllowAutoRedirect=False
The req. Method=Method
The req. Timeout=Timeout

'upward way, set parameters
If method. The ToUpper () & lt;> "GET" Then
Dim UrlEncoded As New StringBuilder ()
Dim reserved As/Char ()={"?" C, "=" c "& amp;" C}
Dim SomeBytes As Byte ()=Nothing

If paramList IsNot Nothing Then
Dim paramBuilder As the New System. Text. StringBuilder ()
Dim paramstr As [String]=Nothing
For li As Integer=0 To paramList. Keys. The Count - 1
If li & gt; 0 Then
ParamBuilder. Append (" & amp;" )
End the If
If paramList. Keys (li) & lt;> "" Then
ParamBuilder. Append (paramList. Keys (li))
ParamBuilder. Append ("=")
End the If
ParamBuilder. Append (paramList (paramList Keys (li)))
Next

Paramstr=paramBuilder. ToString ()
SomeBytes=Encoding UTF8. GetBytes (paramstr)

The req. ContentLength=SomeBytes. Length
Dim newStream As Stream=the req. GetRequestStream ()
NewStream. Write (SomeBytes, 0, SomeBytes. Length)
NewStream. Close ()
The Else
The req. ContentLength=0
End the If
End the If


'request response
Res=DirectCast (the req. The method GetResponse (), HttpWebResponse)
M_Status=res. StatusCode
If resetCookie Then
Me. M_cookieheader=the req. CookieContainer. GetCookieHeader (New Uri (url))
End the If

Dim ReceiveStream As Stream=res. GetResponseStream ()

Dim As the sr System. IO. BinaryReader=Nothing
If res. ContentEncoding="gzip" Then
Dim stream As New GZipStream (ReceiveStream, CompressionMode. Decompress)

The sr=New BinaryReader (stream)
The Else
The sr=New BinaryReader (ReceiveStream)
End the If

'read


Dim the read As Byte ()=New Byte (255) {}
Dim the count As Integer=sr. Read (Read, 0, 256)
While the count & gt; 0
Result. The AddRange (GetSubBytes (read, 0, count))
Count=sr. Read (Read, 0, 256)



End While
Catch the ex As Exception
Dim TMP As String=ex. Message
Result. The Clear ()
The Finally
If res IsNot Nothing Then
Res. The Close ()
End the If
End the Try

Return DirectCast (result. ToArray (GetType (Byte), Byte ())
End the Function
  • Related