https://www.zickty.com/gziptotext
Controller.cs
Public Function GetValue() As HttpResponseMessage
Dim objResponse As Object = ""
Dim numeroElementos As Int32 = 0
Dim fecha As Date = Date.Now
Dim departamentoId As String = ""
Dim paramOption As String = Convert.ToString(Request.Headers.GetValues("paramOption").FirstOrDefault())
If Request.Headers.Contains("fecha") Then
fecha = Convert.ToString(Request.Headers.GetValues("fecha").FirstOrDefault())
End If
Select Case paramOption
Case "ObtenerInfoDisponibles"
Dim jResults As String = ObtenerInfoDisponiblesSerializar(fecha)
objResponse = CompressJsonData(jResults)
End Select
End Function
Private Function ObtenerInfoDisponiblesSerializar(fecha As String) As String
Dim sqlQuery As New System.Text.StringBuilder
sqlQuery.Append("ObtenerInfoDisponibles " + fecha & vbCrLf)
Dim dt As DataTable = MSSQL1.QueryDataTable(conexion, sqlQuery.ToString())
If dt.Rows.Count > 0 Then
Return JsonConvert.SerializeObject(dt)
End If
Return Nothing
End Function
Public Function CompressGZip(input As String, Optional encoding As Encoding = Nothing) As Byte()
encoding = If(encoding, Encoding.Unicode)
Dim bytes As Byte() = encoding.GetBytes(input)
Using stream As New MemoryStream()
Using zipStream As New GZipStream(stream, CompressionMode.Compress)
zipStream.Write(bytes, 0, bytes.Length)
Return stream.ToArray()
End Using
End Using
End Function
Function CompressJsonData(jsonData As String) As Byte()
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(jsonData)
Using memoryStream As New MemoryStream()
Using gzipStream As New GZipStream(memoryStream, CompressionLevel.Optimal)
gzipStream.Write(byteArray, 0, byteArray.Length)
End Using
Return memoryStream.ToArray()
End Using
End Function