debugging host refused connection

Discussions related to HTTPAPI (An HTTP Client Package for RPG programming.) http://www.scottklement.com/httpapi/
Post Reply
mitch123123
Posts: 3
Joined: Sat Jul 29, 2023 2:30 am

debugging host refused connection

Post by mitch123123 »

hey all, new to HTTPAPI. trying to post a stmf using a simple http_url_post_stmf
rc = http_url_post_stmf( URL : %trim(filepath) : %trim(responsePath) );
but everytime i try it says host refused connection( going after localhost )
URL :https://localhost:7143/string/string( url is correct tested in postman)
was this api not meant to be used with local host? do i have parameters i am missing?
i know this may be more of a network thing but has anyone ran into this issue before?
here is the log im getting in debug
HTTPAPI Ver 1.45 released 2021-09-20
NTLM Ver 1.4.0 released 2014-12-22
OS/400 Ver V7R4M0

http_url_post_stmf(): entered
getting post file size...
opening file to be sent...
opening file to be received
http_persist_open(): entered
http_long_ParseURL(): entered
DNS resolver retrans: 2
DNS resolver retry : 2
DNS resolver options: x'00000136'
DNS default domain: internal.treeoflife.com
DNS server found: 10.51.100.5
DNS server found: 10.57.100.5
Nagle's algorithm (TCP_NODELAY) disabled.
SetError() #6: connect(1): A remote host refused an attempted connect operation.
stefan@tageson.se
Posts: 12
Joined: Wed Jul 28, 2021 7:55 am
Location: Viken, Sweden
Contact:

Re: debugging host refused connection

Post by stefan@tageson.se »

If you was able to use that exact url sucessfully using postman, it means that the service you want to reach is located on the host you used postman from. So localhost is not applicable when using httpapi. You need to provide a hostname or an ip-address instead of localhost.
mitch123123
Posts: 3
Joined: Sat Jul 29, 2023 2:30 am

Re: debugging host refused connection

Post by mitch123123 »

Sorry to clarify, the API is running locally from a different .NET application On my PC. I did use the localhost URL in postman and that was successful.
Scott Klement
Site Admin
Posts: 658
Joined: Sun Jul 04, 2021 5:12 am

Re: debugging host refused connection

Post by Scott Klement »

The name "localhost" means "the same computer". So if you are connecting from one application on your PC to another, no problem -- but connecting from a separate computer like the IBM i, it will connect to THAT computer. You will need to use the domain name or IP address of the system you want to connect to.

With regards to the message "a remote refused an attempted connect operation" -- this just means that you connected to a host/port that isn't accepting connections right now.

So it makes perfect sense that when you "connect to the same computer" (localhost) from an application on your PC, it works... when you do the same thing from another computer, you are connecting to "the same computer" (the IBM i) and it doesn't have a server running... thus connection is refused.

It's also possible to get this message from a firewall. Firewalls will sometimes send back "connection refused" as a way to tell the application to give up because there's no application on that port -- this is very unusual, though. Most of the time a firewall will just block the connection so the application gets no response (until it eventually times out.) But occasionally, I'll run into a firewall that sends back "connection refused".

At any rate, this isn't a problem with HTTPAPI. It's just relaying the error that was sent from the server.
mitch123123
Posts: 3
Joined: Sat Jul 29, 2023 2:30 am

Re: debugging host refused connection

Post by mitch123123 »

the answer was right under my nose! i did not think about that , it does make perfect sense. well shoot i appreciate the response very much mr klement! :) and thank you stefan i seemed to misunderstand your explanation
Post Reply