How can I keep the spaces on HTTP POST String

JLeePlnr
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!
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!
0
Comments
-
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.asp0 -
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')+'&'
0 -
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-030 -
Slawek_Guzek wrote: »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.
0 -
Or use DotNet
https://msdn.microsoft.com/en-us/library/system.web.httputility.urlencode(v=vs.110).aspxFollow me on my blog juhl.blog0 -
Slawek_Guzek wrote: »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:
Here is my command:
CustName := Replace(COPYSTR(Cust.Name,1,30),'','%20');
Please advise!0 -
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-030 -
Slawek_Guzek wrote: »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
0 -
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-030 -
Will do. Thanks @Slawek_Guzek0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions