How can I keep the spaces on HTTP POST String

JLeePlnrJLeePlnr Member Posts: 26
Hello,

I use 'Microsoft XML, v6.0'.XMLHTTP automation and "POST" method to send form data to the www server.

The problem that I have, all spaces are being removed when they are getting posted to the www server.

OrderID=ABC 123 DEF -> ABC123DEF
CustName=JOHN ALEXANDER BELL -> JOHNALEXANDERBELL

How can I resolve this?

Here is my snippet:
Variable:
XMLHTTP -> 'Microsoft XML, v6.0'.XMLHTTP

GLSetup.GET;
IF ISCLEAR(XMLHTTP) THEN CREATE(XMLHTTP);
XMLHTTP.open('POST', GLSetup."URL", FALSE);
XMLHTTP.setRequestHeader('Content-Type: ', GLSetup."Request Header");

OrderId :='ORDERID='+OrderId+'&';
Amount := 'AMOUNT='+DELCHR(FORMAT(ROUND(Amount,0.01,'>')*100),'=',',')+'&';
Currency := 'CURRENCY='+'GBP'+'&';
CardNo := 'CARDNO='+DELCHR(DELCHR(CardNumber,'=',' -'),'=',' ')+'&';
ExDate :='EXPDATE='+ExpirationMonth+ExpirationYear+'&';
CustName := 'NAME='+COPY(Customer.Name,1,30)+'&'

StrtoPost := OrderId + Amount + Currency + CardNo + ExDate + CustName;
XMLHTTP.send(StrtoPost);

Thanks for helping!

Comments

  • robbonickrobbonick Member Posts: 40
    Hi, you might be able to encode the spaces into the URL with the right ASCII Encoding Reference.

    So for an example the name could be formatted like so -
    JOHN%20ALEXANDER%20BELL
    

    See this article for reference - https://w3schools.com/tags/ref_urlencode.asp
  • JLeePlnrJLeePlnr Member Posts: 26
    edited 2018-05-31
    robbonick wrote: »
    Hi, you might be able to encode the spaces into the URL with the right ASCII Encoding Reference.

    So for an example the name could be formatted like so -
    JOHN%20ALEXANDER%20BELL
    

    See this article for reference - https://w3schools.com/tags/ref_urlencode.asp

    Hi @robbonick , thanks for responding!

    Any success story on using CONVERTSTR for this?

    Because I got this error when trying:
    CustName := 'NAME='+CONVERTSTR(COPY(Customer.Name,1,30),'','%20')+'&'

    9qca1194ifxo.png





  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    CONVERTSTR is more mapping function rather than conversion. It can only replace one single character by another single character.

    You need to build custom replace function. It may look like this:
    REPLACE(SrcText : Text[1000];ReplaceFrom : Text[30];ReplaceTo : Text[30]) OutText : Text[1000]
    WHILE STRPOS(SrcText, ReplaceFrom) > 0 DO 
      SrcText := COPYSTR(SrcText,1,STRPOS(SrcText, ReplaceFrom)-1)
        + ReplaceTo
        + COPYSTR(SrcText,STRPOS(SrcText, ReplaceFrom)+STRLEN(ReplaceFrom));
    EXIT(SrcText);
    


    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • JLeePlnrJLeePlnr Member Posts: 26
    h6a8jpxf17o0.png
    CONVERTSTR is more mapping function rather than conversion. It can only replace one single character by another single character.

    You need to build custom replace function. It may look like this:
    REPLACE(SrcText : Text[1000];ReplaceFrom : Text[30];ReplaceTo : Text[30]) OutText : Text[1000]
    WHILE STRPOS(SrcText, ReplaceFrom) > 0 DO 
      SrcText := COPYSTR(SrcText,1,STRPOS(SrcText, ReplaceFrom)-1)
        + ReplaceTo
        + COPYSTR(SrcText,STRPOS(SrcText, ReplaceFrom)+STRLEN(ReplaceFrom));
    EXIT(SrcText);
    


    Thank you for being resourceful and helpful @Slawek_Guzek !! Appreciate your helps!

    I'll try it out and let you know.


  • JLeePlnrJLeePlnr Member Posts: 26
    CONVERTSTR is more mapping function rather than conversion. It can only replace one single character by another single character.

    You need to build custom replace function. It may look like this:
    REPLACE(SrcText : Text[1000];ReplaceFrom : Text[30];ReplaceTo : Text[30]) OutText : Text[1000]
    WHILE STRPOS(SrcText, ReplaceFrom) > 0 DO 
      SrcText := COPYSTR(SrcText,1,STRPOS(SrcText, ReplaceFrom)-1)
        + ReplaceTo
        + COPYSTR(SrcText,STRPOS(SrcText, ReplaceFrom)+STRLEN(ReplaceFrom));
    EXIT(SrcText);
    


    Hi @Slawek_Guzek

    I got an empty return using your snippet:
    of8i0paykcv6.png

    Here is my command:
    CustName := Replace(COPYSTR(Cust.Name,1,30),'','%20');

    Please advise!
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    I guess you should call the Replace function like this:
    CustName := Replace(COPYSTR(Cust.Name,1,30),' ','%20');
    //                                           ^ here is the difference
    
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • JLeePlnrJLeePlnr Member Posts: 26
    edited 2018-06-05
    I guess you should call the Replace function like this:
    CustName := Replace(COPYSTR(Cust.Name,1,30),' ','%20');
    //                                           ^ here is the difference
    

    Hi @Slawek_Guzek ,

    I corrected the code and called the function as per your suggestion but I still get an empty Customer Name.
    Please advise.

    Thanks
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Please use Debugger. Check yourself what is passed a in the SrcText variable, chop the function into smaller pieces to see what each statement returns.
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • JLeePlnrJLeePlnr Member Posts: 26
    Will do. Thanks @Slawek_Guzek
Sign In or Register to comment.