Cannot connect to localhost with cURL on Command Prompt

吃可爱长大的小学妹 提交于 2019-12-10 12:25:44

问题


I've just installed cURL on my hard-drive in order to use for testing with my localhost (on the command prompt). However I cannot connect to any port. You can see the directory and my input below:

C:\Users\me\curl\src>curl -v http://localhost:9000

which gives me:

  • Rebuilt URL to: http://localhost:9000/
  • timeout on name lookup is not supported
  • Trying ::1...
  • TCP_NODELAY set
  • Trying 127.0.0.1...
  • TCP_NODELAY set
  • connect to ::1 port 9000 failed: Connection refused
  • connect to 127.0.0.1 port 9000 failed: Connection refused
  • Failed to connect to localhost port 9000: Connection refused
  • Closing connection 0 curl: (7) Failed to connect to localhost port 9000: Connection refused

Perhaps I should have added that I am using IntelliJ and have since enabled cURL on the harddrive (allowing me to access it from any directory); prompting me to try the following:

C:\Users\me\scala\play\my-project>curl -v http://localhost:9000/

which returns:

  • timeout on name lookup is not supported
  • Trying ::1...
  • TCP_NODELAY set
  • connect to ::1 port 9000 failed: Connection refused
  • Trying 127.0.0.1...
  • TCP_NODELAY set
  • connect to 127.0.0.1 port 9000 failed: Connection refused
  • Failed to connect to localhost port 9000: Connection refused
  • Closing connection 0 curl: (7) Failed to connect to localhost port 9000: Connection refused

So it seems that port 9000 is not open. And I am now thinking that this needs to be configured within intelliJ - here - but this looks as though it is only supported on the Ultimate Edition. This might be the cause of the issue that I am having. It may be helpful to others but it would be good to be sure of this if anyone does have any more information.


回答1:


This means that your application is not started yet (so it isn't actually listening on port 9000)

You should add a run configuration in IntelliJ (Run > Edit Configurations > + > Play 2 App) and run it before doing your curl call.

Another way to start your application is just to open a terminal in your project folder, and run sbt run.




回答2:


Try the following server code while running curl:

import java.net._
import java.io._
import scala.io._

val server = new ServerSocket(9000)
while (true) {
    val serv = server.accept()

    val in = new BufferedSource(serv.getInputStream()).getLines()
    val out = new PrintStream(serv.getOutputStream())

    out.println(in.next())
    out.flush()
    serv.close()
}


来源:https://stackoverflow.com/questions/44326251/cannot-connect-to-localhost-with-curl-on-command-prompt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!