Author Topic: LAMW: jHttpClient - how to make soap call? (http POST) - little workaround  (Read 1460 times)


  • Newbie
  • Posts: 4
First of all: to all LAMW group members: Your work is GREAT !!!!

I try to use android as a client of my soap server app as I used to on wince target.
It seems on android target this is very, very different.

I coud not achieve jHttpClient making calls to soap server. (Maybe I was completely wrong in a way doing that - if so - please lighten me up)
I tried to do raw POST, but xml part was always mangled. Server replied with an error.

I looked under the hood :) and I figured out workaround.

Below is little example code:

Code: Pascal  [Select]
  1.   jHttpClient1.ClearNameValueData;
  2.   jHttpClient1.AddClientHeader('Content-Type','text/xml; charset=utf-8');
  3.   jHttpClient1.AddClientHeader('SOAPAction', '"urn:OSWIntf-IOSW#Wersja"');
  5.   content:='<?xml version="1.0" encoding="UTF-8"?>'#13#10
  6.   +'<SOAP-ENV:Envelope xmlns:SOAP-ENV="" xmlns:ns1="urn:OSWIntf-IOSW" '
  7.   +'xmlns:xsd="" xmlns:SOAP-ENC="" '
  8.   +'SOAP-ENV:encodingStyle="">'
  9.   +'<SOAP-ENV:Body><ns1:Wersja/></SOAP-ENV:Body></SOAP-ENV:Envelope>';
  11.   jHttpClient1.AddNameValueData('BODY',content);
  13.   jHttpClient1.PostNameValueDataAsync('');

"Wersja" is function name I try to call at the server side.

Of course in my POST instead of expected raw xml data was: BODY=<?xml version="1.0"....   but encoded as: BODY==3c=3fxml version=3d1.0=3d........

When I changed some lines of getPostDataString function in a file placed in: C:\lamw\lazandroidmodulewizard\java\lamwdesigner

(starting at line # 163)


Code: Pascal  [Select]
  2.               result.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
  3.               result.append("=");
  4.               result.append(URLEncoder.encode(entry.getValue(), "UTF-8"));


Code: Pascal  [Select]
  1.        if (entry.getKey().equals("BODY")==true) {              
  2.          result.append(entry.getValue());
  3.         } else {
  4.               result.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
  5.               result.append("=");
  6.               result.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
  7.         }

then "BODY" key became special. If it is first key then its name will not be used and its value will not be url encoded and xml structure will be fine for soap server.

I have two questions here: Is there any better way to consume soap services wiyh LAMW? Is there possibility to (somehow) use WST package?


  • Hero Member
  • *****
  • Posts: 1316
Re: LAMW: jHttpClient - how to make soap call? (http POST) - little workaround
« Reply #1 on: September 22, 2017, 11:20:35 pm »
(1)I think the issue is how  android api handle:
when  we have others "=" in "content"...   I will try some solution!
(2)To use FPC "FCL" core, often we need to copy the source code to your project "jni"  folder ....

Example: To use  "fphttpclient" copy "fphttpclient.pp",  "httpdefs.pp" and "httpprotocol.pp" to your project "jni" folder
« Last Edit: September 23, 2017, 03:00:54 am by jmpessoa »
Lamw: Lazarus Android Module Wizard


  • Hero Member
  • *****
  • Posts: 1316

I improved jHttpClient!

Some general solution:

Code: Pascal  [Select]
  1. jHttpClient1.SetUnvaluedNameData('BODY'); //disregard nameData 'BODY'
  3. jHttpClient1.SetEncodeValueData(False);  //not encode ValueData
  5. jHttpClient1.AddNameValueData('BODY',content);
  7. jHttpClient1.PostNameValueDataAsync('');
« Last Edit: March 25, 2019, 08:06:12 am by jmpessoa »
Lamw: Lazarus Android Module Wizard

Robert Gilland

  • Full Member
  • ***
  • Posts: 118
Just a quick question why were not these changes available in Lazarus -> Online Package Manager - LAMW --> Update?