Question Lowell Buschert · Feb 25, 2024

Getting a response on an httpRequest from objectscript client to Python Server

I am sending an httpRequest from ObjectScript to a python server.   I am not receiving a response in OS
 
OS config On the client side

// Create an HTTP request object
    Set httpRequest = ##class(%Net.HttpRequest).%New()
    
    // Set the server URL
    Set httpRequest.Server = "http://127.0.0.1:8080"
    
    // Set content type to JSON
    Set httpRequest.ContentType = "application/json"

    // Clear any existing entity body"{""name"": ""Lowell Buschert"", ""dob"": ""1970-12-09"", ""address"": ""XXXXX""}"
    do httpRequest.EntityBody.Clear()
    //Set httpRequest.EntityBody = "{""name"": ""Lowell Buschert"", ""dob"": ""1970-12-09"", ""address"": ""XXXXX""}"

    Set httpRequest.ContentType = "application/json"  // Set the content type to JSON
 
    Set status = httpRequest.Post("/collect_patient_information")

On the server side

When I enter the Server IP into the browser, an form pops up 
I enter some data on the form       
Enter Patient Information
Name:
lowell buschert

Date of Birth:
1970-12-09

Address:
xxx

SUBMIT

The input is formatted with value pairs into a JSON structure

{""name"": ""Lowell Buschert"", ""dob"": ""1970-12-09"", ""address"": ""xxx""}"
and click on submit 

127.0.0.1 - - [25/Feb/2024 04:21:34] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [25/Feb/2024 04:21:35] "GET /favicon.ico HTTP/1.1" 404 -
Formatted Patient Data: {'name': 'lowell buschert', 'dob': '1970-12-09', 'address': 'xxx'}
127.0.0.1 - - [25/Feb/2024 04:21:45] "POST /collect_patient_information HTTP/1.1" 200 -

In OS ,  I displayed some information 
httpRequest: http://127.0.0.1:8080 application/json 2@%Library.GlobalBinaryStream  

status: 0 /«http://127.0.0.1:8080:80 HSFNDý!e^zOpen+59^%Net.HttpRequest.1^2!e^zSend+30^%Net.HttpRequest.1^1 e^zPost+1^%Net.HttpRequest.1^1%e^zCollectInfo+19^OBHG.AIR.Main.1^1'e^zGetPatientInfo+2^OBHG.AIR.Main.1^1 e^zOnStart+3^OBHG.AIR.Main.1^1&d^zDebugStub+40^%Debugger.System.1^1 d^^^0 

statusline:  reasonPhrase: StatusReasonPhrase: HTTP request failed with status code: Response: 

Product version: IRIS 2023.1

Comments

Enrico Parisi · Feb 25, 2024

First I'd suggest to change:

 Set httpRequest.Server = "http://127.0.0.1:8080" 

to:

 Set httpRequest.Server = "127.0.0.1" 
 Set httpRequest.Port = "8080" 

I would also check the status after:

Set status = httpRequest.Post("/collect_patient_information")

And then try again.

0
Lowell Buschert · Feb 25, 2024

I set  

Set httpRequest.Server = "127.0.0.1
 Set httpRequest.Port = "8080 

Request from OS         Set status = httpRequest.Post("/collect_patient_information")

from the server side log   

Response  127.0.0.1 - - [25/Feb/2024 10:44:58] "POST /collect_patient_information HTTP/1.1" 200 -
 

Status on ObjectScript on Response. 

httpRequest: 127.0.0.1 application/json 2@%Library.GlobalBinaryStream status: 0 %«127.0.0.1:8080HSFNDý!e^zOpen+59^%Net.HttpRequest.1^2!e^zSend+30^%Net.HttpRequest.1^1 e^zPost+1^%Net.HttpRequest.1^1%e^zCollectInfo+20^OBHG.AIR.Main.1^1'e^zGetPatientInfo+2^OBHG.AIR.Main.1^1 e^zOnStart+3^OBHG.AIR.Main.1^1&d^zDebugStub+40^%Debugger.System.1^1d^^^0 statusline: reasonPhrase: StatusReasonPhrase: HTTP request failed with status code: Response:
 

Something is getting lost between Server  Python and client OS

0
Enrico Parisi · Feb 26, 2024

To properly display the status use:

Set statusText=$system.Status.GetErrorText(status)

0
Lowell Buschert · Feb 26, 2024

This is kinda related.     Is there another term for httpRequest.httpVerb in Intersystems ObjectScript

0
Lowell Buschert · Feb 28, 2024

I have it working.   The important thing with flask are the routes which establish a connection between the client and the server.   Config on both C and CS contain the same route names.    

0