bash 以下网址:curl 无法解析主机“GET”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24221642/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
following url: curl couldn't resolve host 'GET'
提问by bit
I have a page (realized with a php framework) that add records in a MySQL db in this way: www.mysite.ext/controller/addRecord.php?id=number that add a row in a table with the number id passed via post and other informations such as timestamp, etc. So, I movedo my eintire web applicazione to another domain and all HTTP requests works fine from old to new domain. Only remaining issue is the curl: I wrote a bash script (under linux) that run curl of this link. Now, obviously it does not works because curl returns an alert message in which I read the page was moved. Ok, I edited the curl sintax in this way
我有一个页面(用 php 框架实现),它以这种方式在 MySQL 数据库中添加记录:www.mysite.ext/controller/addRecord.php?id=number 在表中添加一行,编号 id 通过发布和其他信息,例如时间戳等。因此,我将整个网络应用程序移至另一个域,并且所有 HTTP 请求从旧域到新域都可以正常工作。唯一剩下的问题是 curl:我写了一个 bash 脚本(在 linux 下)运行此链接的 curl。现在,显然它不起作用,因为 curl 返回一条警报消息,我在其中阅读了页面已移动。好的,我以这种方式编辑了 curl 语法
#! /bin/sh
link="www.myoldsite.ext/controlloer/addRecord.php?id=number"
curl --request -L GET $link
I add -Lto follow url in new location but curl returns the error I wrote in this topic title. It would be easier if I could directly modify the link adding the new domain but I do not have physical access to all devices.
我添加-L以在新位置跟踪 url,但 curl 返回我在此主题标题中写的错误。如果我可以直接修改添加新域的链接,但我没有对所有设备的物理访问权限,那会更容易。
回答by Yes Barry
GET
is the default requesttype for curl
. And that's not the way to set it.
GET
是 的默认请求类型curl
。这不是设置它的方式。
curl -X GET ...
That is the way to set GET
as the method keywordthat curl uses.
这就是设置GET
为curl 使用的方法关键字的方法。
It should be noted that curl selects which methods to use on its own depending on what action to ask for. -d will do POST, -I will do HEAD and so on. If you use the --request / -X option you can change the method keyword curl selects, but you will not modify curl's behavior. This means that if you for example use -d "data" to do a POST, you can modify the method to a PROPFIND with -X and curl will still think it sends a POST. You can change the normal GET to a POST method by simply adding -X POST in a command line like:
应该注意的是,curl 根据要请求的操作自行选择要使用的方法。-d 会做 POST,-I 会做 HEAD 等等。如果您使用 --request / -X 选项,您可以更改 curl 选择的方法关键字,但您不会修改 curl 的行为。这意味着,例如,如果您使用 -d "data" 进行 POST,则可以使用 -X 将该方法修改为 PROPFIND,curl 仍会认为它发送了 POST。您可以通过在命令行中简单地添加 -X POST 将普通 GET 更改为 POST 方法,例如:
curl -X POST http://example.org/
... but curl will still think and act as if it sent a GET so it won't send any request body etc.
...但 curl 仍然会像发送 GET 一样思考和行动,因此它不会发送任何请求正文等。
More here: http://curl.haxx.se/docs/httpscripting.html#More_on_changed_methods
更多信息:http: //curl.haxx.se/docs/httpscripting.html#More_on_changed_methods
Again, that's not necessary. Are you sure the link is correct?
再说一遍,这没有必要。你确定链接正确吗?