cpp-httplib icon indicating copy to clipboard operation
cpp-httplib copied to clipboard

Error::BindIPAddress

Open kubistika opened this issue 5 years ago • 4 comments

Hi,

I'm using this awesome library to perform some http requests from my c++ utility application. However, I keep getting Error::BindIPAddress from the library and I cannot find out why.

I'm working on Mac and trying to send http request to an http server running on localhost:8080, the code looks like that:

httplib::Client cli("http://localhost:8080");
cli.Post(...)

Thanks a lot!

kubistika avatar Mar 15 '21 10:03 kubistika

@kubistika, thank you for the feedback, but I don't know why either. Could you try cd test; make to see what happens? Also does curl with the same POST request work on your machine? Hope it helps!

yhirose avatar Mar 15 '21 11:03 yhirose

BindIPAddress should only be happening in server mode. If it is really happening in client mode, then something strange is going on. Otherwise, it might be that port 8080 is already occupied and the server cannot use it, or that the server process is prohibited from listening on localhost interface for some reason.

PixlRainbow avatar Mar 17 '21 07:03 PixlRainbow

BindIPAddress should only be happening in server mode. If it is really happening in client mode, then something strange is going on. Otherwise, it might be that port 8080 is already occupied and the server cannot use it, or that the server process is prohibited from listening on localhost interface for some reason.

Yea, that's why I think something is weird because I'm not even using the http server of this library.

kubistika avatar Mar 18 '21 19:03 kubistika

Actually, nevermind. Inspecting the code, BindIPAddress can occur on the client. Wonder what your ifconfig looks like.

Googling, it appears that some other libraries experience this issue if not all the fields of certain socket-related struct have been initialized to 0, and stackoverflow lists that similar issues may occur because certain Mac OS versions lack named aliases for the loopback interface by default. Not sure if any of these are relevant to your issue.

PixlRainbow avatar Mar 19 '21 08:03 PixlRainbow