How do you get the response as a string using the http_url_get method in rpg - rpgle

Good day,
I am trying to consume a get method on a server hosted locally.
rc = http_url_get('http://sss:13013/cgi-bi/sendms?'
+ 'username=cous&pas'
+ 'to=' + vCell + '&text=' + %TRIM(vSMSText):
'/tmp/httptest.html');
I am using a library called HTTPAPI its from https://www.scottklement.com/httpapi/
I am trying to figure out how to get the response of the call as a string.
The Variable rc contains a integer response code but no response, I am assuming it gets downloaded to the /tmp/httptest.html parameter specified. But I want it as a string as I want to process the response as a string. I do not know if there is a extra parameter that I can use to store the result of the call.
I have tried the http_string method but I get an error that the method is undefined, I think the my client is using an old version of the HTTPAPI lib.
Is it possible to use the http_url_get function to return the response as a string?.

if you want to get a string response, use Klement's HTTP_req(). It is flexible enough to get a file or a string (and use a file or a string to send a request). You can play with *omit to select the way you can make a GET (on other actions).

Related

What is this structure coming from a fetch that returns a octet-stream?

I'm tring to retrieve a list of files from an API using axios, in Node.js. What I get is what I assume is an ArrayBuffer string. I'm using the following code:
axios.get('http://api.com/filesList').then(response => {
console.log(response.data);
});
This is what I get (changed numbers and letters a bit to hide potential priv info):
$97cceb28↕$sad28sdj-askd-3294-3jh9→--Account_123456789 �����0*$97cceb282¶2022-11-30.csv"�☺
$97cceb28↕$sad28sdj-askd-3294-3jh9→--Account_123456789 ���0*$97cceb282¶2022-11-26.csv"�☺
$97cceb28↕$sad28sdj-askd-3294-3jh9→--Account_123456789 �໑�0*$97cceb282¶2022-11-19.csv"�☺
I know for a fact that I'm supposed to receive certain information for each file of this list, at least which account is associated to them and their name. I did a little digging and added responseType: 'arraybuffer' to the function and then it output a <Buffer 22 be 01...> kind of response. I then tried a method to convert it to a string but I end up getting the result I had without setting the response type.
So, what kind of string data is this and how do I convert it to an object/JSON? Is there a way to decode this structure?
Thank you all in advance.

How can i post data using this code below and also tell user to wait while sending message

Iam currently using b4a for android
here is the error which comes
enter code here
',' expected.`enter code here`
enter code here
Dim j As HttpJob
j.Initialize("", Me)
j.PostString($"http://kccug.com/KabojjaApp/RecieveSMS.ashx?customerId=${act}&s=${edtMessage.Text}&d=${getdate(DateTime.Now)}&id=${NewID}&ph=${phone}&f=${sx}"$ )
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Log(j.GetString)
End If
enter code here
You are using j.PostString which sends a post request. However, you are not using it correctly. j.PostString requires a second parameter: the post data. B4A expects you to put in a comma and the second paramter after the url, but you are only giving 1 parameter (the url) to the function. However, looking at your URL, it seems like your backend is handling stuff through GET requests only anyway, not POST. So really, what you should be using is j.Download. Try this code:
Dim j As HttpJob
j.Initialize("", Me)
j.Download($"http://kccug.com/KabojjaApp/RecieveSMS.ashx?customerId=${act}&s=${edtMessage.Text}&d=${getdate(DateTime.Now)}&id=${NewID}&ph=${phone}&f=${sx}"$)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Log(j.GetString)
End If
It's exactly the same, but it uses Download instead of PostString.

Get wrong parameter from get method in nodejs

I'm trying to send get method request and want to pass value in URL.
Like my api look like
app.get('/api/getlocation/:customerName', customer.getlocation);
For call this I wrote in postman
localhost:8080/api/getlocation/:customerName=kumbhani
For test
var customerName = req.params.customerName;
console.log('name', customerName); // =kumbhani
It returns name with = sign - I want only kumbhani
The colon character in the path in Express has a special meaning: whatever you put in the URL after getLocation/ will be put in req.params.customerName.
This means in Postman, you should actually call this URL:
localhost:8080/api/getlocation/kumbhani
→ See related question.

Arduino - Passing long String to a Library

I am trying to write my first big Arduino Library, in this case to control the ESP8266.
I would like to pass as parameter the WEBSITE address to a method that will do the GET request so I need to send two long Strings:
(1) Fix part of the website url
(2) json with the data to add to
the request
1) The fix part is this:
#define WEBPAGE "/mywebsiteURLfolder/post.php?json={"
So I call my library method:
myESPinstanceSOFT.Send_OnlineService(1, HOST, WEBSITE, 9);
And my library should receive it and use to create a final String that will be used to send it via Serial to the ESP8266:
bool ESP8266Class::Send_OnlineService(byte type, String HOST, String WEBPAGE, int Node_ID){
String request = "GET ";
request += WEBPAGE;
request += "Node_ID:";
etc etc
Given that WEBSITE is a fix string. How can I save it in flash and just point to it when constructing the request string?
Thank you very much

Monotouch/iPhone - Call to HttpWebRequest.GetRequestStream() connects to server when HTTP Method is DELETE

My Scenario:
I am using Monotouch for iOS to create an iPhone app. I am calling ASP.NEt MVC 4 Web API based http services to login/log off. For Login, i use the POST webmethod and all's well. For Logoff, i am calling the Delete web method. I want to pass JSON data (serialized complex data) to the Delete call. If i pass simple data like a single string parameter as part of the URL itself, then all's well i.e. Delete does work! In order to pass the complex Json Data, here's my call (i have adjusted code to make it simple by showing just one parameter - UserName being sent via JSON):
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://localhost/module/api/session/");
req.ContentType = "application/json";
req.CookieContainer = jar;
req.Method = "Delete";
using (var streamWrite = new StreamWriter(req.GetRequestStream()))
{
string jSON = "{\"UserName\":\"" + "someone" + "\"}";
streamWrite.Write(jSON);
streamWrite.Close();
}
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
on the server, the Delete method looks has this definition:
public void Delete(Credentials user)
where Credentials is a complex type.
Now, here's the issue!
The above code, gets into the Delete method on the server as soon as it hits:
req.GetRequestStream()
And hence the parameter sent to the Delete method ends up being null
And here's the weird part:
If i use the exact same code using a test VS 2010 windows application, even the above code works...i.e it does not call Delete until req.GetResponse() is called! And in this scenario, the parameter to the Delete method is a valid object!
QUESTION
Any ideas or Is this a bug with Monotouch, if so, any workaround?
NOTE:
if i change the Delete definition to public void Delete(string userName)
and instead of json, if i pass the parameter as part of the url itself, all's well. But like i said this is just a simplified example to illustrate my issue. Any help is appreciated!!!
This seems to be ill-defined. See this question for more details: Is an entity body allowed for an HTTP DELETE request?
In general MonoTouch (based on Mono) will try to be feature/bug compatible with the Microsoft .NET framework to ease code portability between platforms.
IOW if MS.NET ignores the body of a DELETE method then so will MonoTouch. If the behaviour differs then a bug report should be filled at http://bugzilla.xamarin.com

Resources