Page 1 of 1

Problem sending data using HttpEndpoint

Posted: Mon May 02, 2022 11:06 am
by rdonnay
The below snippet of code shows how I have been sending BASE64 data to our Web Service.
This has been working fine until today. There have been no code changes on either end.

The Base64 string that gets sent is the correct length but some characters have been changed from upper case to lower case.
I have tried changing content type and accept type to no avail. Any ideas?

Code: Select all

Sent:
jvberi0xljqkjdp0zoekmsawig9iago8paovq3jlyxrpb25eyxrlkeq6mjaymja1mdiwote1ntctmdynmdankqovq3jlyxrvcihqrezzagfyccaxljuwljuxnd ...

Received:
JVBERi0xLjQKJdP0zOEKMSAwIG9iago8PAovQ3JlYXRpb25EYXRlKEQ6MjAyMjA1MDIwOTE1NTctMDYnMDAnKQovQ3JlYXRvcihQREZzaGFycCAxLjUwLjUxND ...

Code: Select all

cVehDoc := File2Base64(DC_Path(AppName(.t.))+'OutputDoc_1.Pdf')
cMedDoc := File2Base64(DC_Path(AppName(.t.))+'OutputDoc_2.Pdf')

Base642File(cVehDoc,'Veh.Pdf')
Base642File(cMedDoc,'Med.Pdf')

MemoWrit('Veh.txt',cVehDoc)
MemoWrit('Med.txt',cMedDoc)

wtf Len(cVehDoc), Len(cMedDoc)

IF Empty(cVehDoc)
  DCMSGBOX 'Cannot open OutputDoc_1.Pdf'
  RETURN .f.
ENDIF

IF Empty(cMedDoc)
  DCMSGBOX 'Cannot open OutputDoc_2.Pdf'
  RETURN .f.
ENDIF

cUrl := WebServiceUrl() + 'SubmitSignedLeaseDocuments'
oHC := HttpClient():new( cUrl )
oHC:httpRequest:setParameter( "lseid", cLseID )
oHC:httpRequest:setParameter( "userID",'0007' )
oHC:httpRequest:setParameter( "vehicle_document", cVehDoc )
oHC:httpRequest:setParameter( "medallion_document", cMedDoc )
oHC:httpRequest:setContentType("multipart/form-data")

Re: Problem sending data using HttpEndpoint

Posted: Thu May 05, 2022 6:46 am
by skiman
Hi Roger,

Have you found the cause of this problem?

Re: Problem sending data using HttpEndpoint

Posted: Sat May 07, 2022 7:38 pm
by rdonnay
Have you found the cause of this problem?
Hi Chris.

I haven't really found the cause but I found a few workarounds.
I changed the content-type to "application/x-www-form-urlencoded".
That caused all of the BASE64 characters to be sent correctly except for the "+" characters which were replaced by SPACE characters.

The workaround was an Strtran() of the BASE64 string to replace all SPACE characters with "+" characters.

Re: Problem sending data using HttpEndpoint

Posted: Sun May 08, 2022 11:22 pm
by k-insis
"This has been working fine until today. There have been no code changes on either end."

If there was "no code change" ... there was code change . Did you consider some shared library used by handling routines at server side was updated ? Do you manage server too?



rdonnay wrote: Sat May 07, 2022 7:38 pm
Have you found the cause of this problem?
Hi Chris.

I haven't really found the cause but I found a few workarounds.
I changed the content-type to "application/x-www-form-urlencoded".
That caused all of the BASE64 characters to be sent correctly except for the "+" characters which were replaced by SPACE characters.

The workaround was an Strtran() of the BASE64 string to replace all SPACE characters with "+" characters.

Re: Problem sending data using HttpEndpoint

Posted: Mon May 09, 2022 5:54 am
by rdonnay
If there was "no code change" ... there was code change
I agree with that assessment, however any changes were not in the source code or in Xbase++.
It may be an issue with Windows IP socket system.
I rebooted but that made no difference.

The test was entirely on a local computer, both the client and the server.

Re: Problem sending data using HttpEndpoint

Posted: Tue May 10, 2022 12:16 am
by k-insis
Local machine with Windows. Might there be some shared .dll in path that changed to another release (older one with bugs) - I saw problem like that already but with ssl libraries.

That is indeed hard to find out.
rdonnay wrote: Mon May 09, 2022 5:54 am
If there was "no code change" ... there was code change
I agree with that assessment, however any changes were not in the source code or in Xbase++.
It may be an issue with Windows IP socket system.
I rebooted but that made no difference.

The test was entirely on a local computer, both the client and the server.

Re: Problem sending data using HttpEndpoint

Posted: Tue May 10, 2022 2:08 am
by skiman
Hi Roger,

Using strtran() in an base64encoded string looks a bit strange/dangerous to me.

There must be a reason why the content is changing from uppercase to lowercase.

I was wondering if this would work:

Code: Select all

oHC:httpRequest:setParameter( "vehicle_document", 'data:application/pdf;base64,'+cVehDoc )
I'm using this kind of syntax when I create JSON with base64encoded documents.

Re: Problem sending data using HttpEndpoint

Posted: Tue May 10, 2022 6:51 am
by rdonnay
Using strtran() in an base64encoded string looks a bit strange/dangerous to me.
At first, it seemed dangerous to me too, but I'm only using this to test some very complicated endpoints and I want to be able to do all of this locally. The client who is using this endpoint has no problem. Also, it works fine if I test the endpoint using a WebBrowser form. It only fails with :httpRequest.
I'm using this kind of syntax when I create JSON with base64encoded documents.
Are you doing this in Xbase++ ?

Re: Problem sending data using HttpEndpoint

Posted: Tue May 10, 2022 7:04 am
by skiman
Hi Roger,

Yes, this is in Xbase++, it is used in my rest-API for BOA.

I'm always using xbbase64encode() from xb2net, but I suppose the function you use to encode isn't the problem.

I use the following for images:
"data:image/jpg;base64,"+xbbase64encode(memoread("xxx.jpg"))

Since data:application/pdf;base64, also exists, I thought this could be a solution.

Do you have a sample of the client and server part that shows the problem?

Re: Problem sending data using HttpEndpoint

Posted: Tue May 10, 2022 7:25 am
by rdonnay
This doesn't work for me.
Apparently, you are using Xb2Net, not HttpClient().