-1

Could anyone advise how to parse "text/plain" content received from HTTPS response using dp:urlopen() in gateway scripting. We can read the response as "readAsBuffer" to save the context but how can we parse the content. If the response content is application/json we can parse with JSON.parse().

In case of json content -

urlopen.open(options, function(error, response) {
            if (error) {
                console.log(error);
            } else {
                
                if (responseStatusCode == 200) {
                    hm.response.statusCode = responseStatusCode;
                    response.readAsBuffer(function(error, Data) {
                        if (error) {
                            console.log(error);
                        } else {
                            hm.response.statusCode = responseStatusCode;
                            var response = JSON.parse(Data);                            
                        }
                    });
                    }
                    
                    }
                    });

Please advise me in this regards?

Virat
  • 77
  • 1
  • 5

1 Answers1

0

Plain text, but its nature, is impossible to parse in the general case. It is freeform text with no structure.

If it was structured text that was mislabelled as plain text and you knew what structure it had then you could run it through a JSON/XML/HTML/YAML/whatever-it-is parser.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335