Highlighted
Visitor.
794 views

Substituting part of request body json with dynamically created string

Hi,

I am facing a strage problem in substituting a string dynamically created by substituting parameter values and sending as part of json body. When I directly send the request with the string the request passes and if I copy the same string to a character pointer and pass the same to the json, the request fails with a http 400 error.

Below is the string I send via char pointer.

char *bodystring="{\\\"ActualScannedBarcodeValue\\\":\\\"XB306247306GB\\\",\\\"Barcode\\\":\\\"XB306247306GB\\\",\\\"barcodeType\\\":\\\"NORMAL\\\",\\\"TimeStamp\\\":\\\"/Date(1481731291688)/\\\",\\\"IsSignatureRequired\\\":false,\\\"Latitude\\\":0.0,\\\"Longitude\\\":0.0,\\\"PackageType\\\":0,\\\"IsScanned\\\":true,\\\"StatusId\\\":1,\\\"IsReturnToSender\\\":false,\\\"IsNeighbourSignatureRequired\\\":false,\\\"IsManualEntry\\\":false,\\\"isAdditionalInfoRequired\\\":false,\\\"isPrepopulated\\\":false,\\\"IsIdentityProofRequired\\\":false,\\\"IsForwardToRecipient\\\":false,\\\"IsForwardToNrc\\\":true}";

converting the string to a parameter

lr_save_string(bodystring,"p_Body"); and attach to the body part as a parameter.

If I send above string directly in the json the request passes, as below

{\"ActualScannedBarcodeValue\":\"XB306247306GB\",\"Barcode\":\"XB306247306GB\",\"barcodeType\":\"NORMAL\",\"TimeStamp\":\"/Date(1481731291688)/\",\"IsSignatureRequired\":false,\"Latitude\":0.0,\"Longitude\":0.0,\"PackageType\":0,\"IsScanned\":true,\"StatusId\":1,\"IsReturnToSender\":false,\"IsNeighbourSignatureRequired\":false,\"IsManualEntry\":false,\"isAdditionalInfoRequired\":false,\"isPrepopulated\":false,\"IsIdentityProofRequired\":false,\"IsForwardToRecipient\":false,\"IsForwardToNrc\":true}

The whole body part is give below.

"Body={\"TimeStamp\":\"/Date({h_Date})/\",\"PackageList\":[{\"ActualScannedBarcodeValue\":\"XB306247306GB\",\"Barcode\":\"XB306247306GB\",\"barcodeType\":\"NORMAL\",\"TimeStamp\":\"/Date(1481731291688)/\",\"IsSignatureRequired\":false,\"Latitude\":0.0,\"Longitude\":0.0,\"PackageType\":0,\"IsScanned\":true,\"StatusId\":1,\"IsReturnToSender\":false,\"IsNeighbourSignatureRequired\":false,\"IsManualEntry\":false,\"isAdditionalInfoRequired\":false,\"isPrepopulated\":false,\"IsIdentityProofRequired\":false,\"IsForwardToRecipient\":false,\"IsForwardToNrc\":true}],\"ManifestId\":0,\"ModuleId\":1,\"ProcessId\":{p_ProcessId},\"LocationId\":{p_LocationId},\"SubProcessId\":{p_SubProcessId},\"BusinessEntityID\":1,\"UserID\":{c_X-PMC-CredentialId},\"MainAltitude\":0.0,\"MainLatitude\":0.0,\"MainLongitude\":0.0}"

Please let me know how I can substitute the body part by saving the same to a char pointer and use as a parameter

 

 

 

0 Likes
1 Reply
Highlighted
Honored Contributor.
Honored Contributor.

Did you try to use DFE for  JSON?

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.