EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Adding headers in PUT request (.net Application)

Also by EldoS: RawDisk
Access locked and protected files in Windows, read and write disks and partitions and more.
#35179
Posted: 12/07/2015 04:49:34
by Leo Lampidis (Basic support level)
Joined: 12/07/2015
Posts: 3

I'm developing a .net windows application that needs to communicate with a server to send Json data with PUT requests. When I'm trying to add headers to the request using the OnPreparedHeaders event and the SetRequestHeader() function I'm getting the following exception: Cannot inflate compressed data. (error code is 100357)
Could you please suggest me a solution to this issue?

My source code is the following:


Imports System.Text
Imports SBHTTPSClient
Imports SBStringList
Imports SBX509
Imports System.IO

Public Class MyRestClient

Private WithEvents httpsClient As TElHTTPSClient

Public Sub New()
SBUtils.Unit.SetLicenseKey("My key is here!")
SBHTTPCRL.Unit.RegisterHTTPCRLRetrieverFactory()
SBHTTPOCSPClient.Unit.RegisterHTTPOCSPClientFactory()
SBHTTPCertRetriever.Unit.RegisterHTTPCertificateRetrieverFactory()

httpsClient = New TElHTTPSClient()
httpsClient.RequestParameters.ContentType = "application/json"
End Sub

Private Function PerformRequest(url As String, jsonBody As String) As String
Dim receivedText As String = ""
httpsClient.ClearRequest()

Using ms As New MemoryStream
httpsClient.OutputStream = ms

httpsClient.Put(url, jsonBody)

receivedText = ASCIIEncoding.UTF8.GetString(ms.ToArray())
ms.Close()
ms.Dispose()
End Using

Return receivedText
End Function

Private Sub httpsClient_OnCertificateValidate(Sender As Object, X509Certificate As TElX509Certificate, ByRef Validate As Boolean) Handles httpsClient.OnCertificateValidate
Validate = True
End Sub

Private Sub httpsClient_OnPreparedHeaders(Sender As Object, Headers As TElStringList) Handles httpsClient.OnPreparedHeaders
httpsClient.SetRequestHeader("Header1", "Value1")
httpsClient.SetRequestHeader("Header2", "Value2")
End Sub

End Class
#35180
Posted: 12/07/2015 04:52:55
by Vsevolod Ievgiienko (EldoS Corp.)

Thank you for contacting us.

Please set httpsClient.UseCompression to 'false'. Our code is already improved to eliminate this issue in the future.

I’ve noticed there is no Support Access Ticket linked to your user account on EldoS site. Technical Support is provided to customers with the linked Support Access Ticket. You will find your Support Access Ticket together with all the details about how to use it in the registration e-mail that we’ve sent to you upon the purchase.

If you are evaluating the product and don't have a license yet, please let us know and then you can have support according to Basic support level. Basic support level includes answering basic technical questions that appear during product evaluation period. We also offer Premium support for a purchase from https://www.eldos.com/support/calc.php . You can use Premium Support to get higher level of assistance during your evaluation of our products.
#35182
Posted: 12/07/2015 06:20:50
by Leo Lampidis (Basic support level)
Joined: 12/07/2015
Posts: 3

Thank you very much for the quick response.

The solution you suggest me works fine but I fine another one issue.
The string that is sending to the server is corrupted with the code above. I'll have to convert the string to byte array and send the byte array.

Code
httpsClient.Put(url, ASCIIEncoding.UTF8.GetBytes(jsonBody))

instead of
Code
httpsClient.Put(url, jsonBody)
#35183
Posted: 12/07/2015 06:26:39
by Vsevolod Ievgiienko (EldoS Corp.)

According to the code the first method should convert a string to UTF8 internally. Could you please clarify how is the string corrupted.
#35184
Posted: 12/07/2015 08:12:45
by Leo Lampidis (Basic support level)
Joined: 12/07/2015
Posts: 3

I used the event OnSendData to get the data that I'm sending to the server. Then I compare the byte array (converted to UTF-8) from the event with the string I'm passing to Put function. The data provided by the event are containing one part of the data I'm passing to Put.
But when I call the Put with Byte array, instead of string, the data provided by the event contain the the whole data I'm passing to Put.
#35185
Posted: 12/07/2015 08:22:19
by Vsevolod Ievgiienko (EldoS Corp.)

OnSendData may be fired multiple times for a single request, so one call may report a part of the date being sent.
Also by EldoS: RawDisk
Access locked and protected files in Windows, read and write disks and partitions and more.

Reply

Statistics

Topic viewed 1576 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!