Problem sending data using HttpEndpoint

Xbase++ 2.0 Build 554 or later
Post Reply
Message
Author
User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Problem sending data using HttpEndpoint

#1 Post 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")
The eXpress train is coming - and it has more cars.

skiman
Posts: 1183
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: Problem sending data using HttpEndpoint

#2 Post by skiman »

Hi Roger,

Have you found the cause of this problem?
Best regards,

Chris.
www.aboservice.be

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Problem sending data using HttpEndpoint

#3 Post 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.
The eXpress train is coming - and it has more cars.

k-insis
Posts: 94
Joined: Fri Jan 28, 2011 4:07 am

Re: Problem sending data using HttpEndpoint

#4 Post 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.

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Problem sending data using HttpEndpoint

#5 Post 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.
The eXpress train is coming - and it has more cars.

k-insis
Posts: 94
Joined: Fri Jan 28, 2011 4:07 am

Re: Problem sending data using HttpEndpoint

#6 Post 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.

skiman
Posts: 1183
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: Problem sending data using HttpEndpoint

#7 Post 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.
Best regards,

Chris.
www.aboservice.be

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Problem sending data using HttpEndpoint

#8 Post 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++ ?
The eXpress train is coming - and it has more cars.

skiman
Posts: 1183
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: Problem sending data using HttpEndpoint

#9 Post 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?
Best regards,

Chris.
www.aboservice.be

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Problem sending data using HttpEndpoint

#10 Post by rdonnay »

This doesn't work for me.
Apparently, you are using Xb2Net, not HttpClient().
The eXpress train is coming - and it has more cars.

Post Reply