【问题标题】:curl: (3) unmatched brace in URL position 1:curl: (3) URL 位置 1 中不匹配的大括号:
【发布时间】:2019-01-19 23:12:50
【问题描述】:

我正在从这里运行 Apache Solr 教程:

http://lucene.apache.org/solr/guide/7_6/solr-tutorial.html

Solr 正在运行,我可以在网络浏览器中运行查询。

教程中提到了我不熟悉的cURL。

我已将CURL 解压缩为C:\Curl 并将Curl 包含在PATH environment variable 中:C:\Curl\curl-7.63.0-win64-mingw\bin

在 Windows 命令提示符下运行以下命令时出现错误。我用谷歌搜索了一个解决方案,但无济于事:

代码如下:

C:\Curl\curl-7.63.0-win64-mingw\bin>curl -X POST -H 'Content-type:application/json' --data-binary '{"add-field": {"name":"name", "type":"text_general", "multiValued":false, "stored":true}}' http://localhost:8983/solr/films/schema

产生以下错误:

curl: (3) unmatched brace in URL position 1:
{name:name,
 ^
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) unmatched close brace/bracket in URL position 12:
stored:true}}'
           ^
{
  "responseHeader":{
    "status":400,
    "QTime":1},
  "error":{
    "metadata":[
      "error-class","org.apache.solr.common.SolrException",
      "root-error-class","org.apache.solr.common.SolrException"],
    "msg":"no stream",
    "code":400}}

我尝试添加 -g 来关闭通配符。

curl -g -X POST -H 'Content-type:application/json' --data-binary '{"add-field": {"name":"name", "type":"text_general", "multiValued":false, "stored":true}}' http://localhost:8983/solr/films/schema

这产生了一个几乎相同的错误:

C:\Curl\curl-7.63.0-win64-mingw\bin>curl -g -X POST -H 'Content-type:application/json' --data-binary '{"add-field": {"name":"name", "type":"text_general", "multiValued":false, "stored":true}}' http://localhost:8983/solr/films/schema

curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
{
  "responseHeader":{
    "status":400,
    "QTime":1},
  "error":{
    "metadata":[
      "error-class","org.apache.solr.common.SolrException",
      "root-error-class","org.apache.solr.common.SolrException"],
    "msg":"no stream",
    "code":400}}

然后我尝试删除单引号并转义双引号,但随后出现以下错误:

curl -g -X POST -H Content-type:application/json --data-binary {\"add-field\": {\"name\":\"name\", \"type\":\"text_general\", \"multiValued\":false, \"stored\":true}} http://localhost:8983/solr/films/schema

curl:(3) URL 使用错误/非法格式或缺少 URL curl: (3) URL 使用错误/非法格式或缺少 URL curl: (3) URL 使用错误/非法格式或缺少 URL curl: (3) URL 使用错误/非法格式或缺少 URL { “响应头”:{ “状态”:500, "QTime":4}, “错误”:{ "msg":"过早的 EOF: char=(EOF),position=11 AFTER=''", "trace":"org.noggit.JSONParser$ParseException: Premature EOF: char=(EOF),position=11 AFTER=''\r\n\tat org.noggit.JSONParser.err(JSONParser.java:419)\ r\n\tat org.noggit.JSONParser.next(JSONParser.j ava:973)\r\n\tat org.noggit.JSONParser.nextEvent(JSONParser.java:1061)\r\n\tat org.apache.solr.common.util.CommandOperation.parse(CommandOperation.java:285) \r\n\tat org.apache.solr.common.util.Command Operation.readCommands(CommandOperation.java:350)\r\n\tat org.apache.solr.common.util.CommandOperation.readCommands(CommandOperation.java:326)\r\n\tat org.apache.solr.api。 ApiBag.getCommandOperations(A piBag.java:289)\r\n\tat org.apache.solr.servlet.HttpSolrCall.getCommands(HttpSolrCall.java:1073)\r\n\tat org.apache.solr.servlet.SolrRequestParsers$1.getCommands(SolrRequestParsers .java:245)\r\n\tat o rg.apache.solr.schema.SchemaManager.performOperations(SchemaManager.java:77)\r\n\tat org.apache.solr.handler.SchemaHandler.handleRequestBody(SchemaHandler.java:90)\r\n\tat org. apache.solr.handler.requ estHandlerBase.handleRequest(RequestHandlerBase.java:199)\r\n\tat org.apache.solr.core.SolrCore.execute(SolrCore.java:2541)\r\n\tat org.apache.solr.servlet.HttpSolrCall。执行(HttpSolrCall.java:709)\ r\n\tat org.apache.solr.servlet.HttpSolrCall.call(HttpSolrCall.java:515)\r\n\tat org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:377)\r\ n\tat org.apache.solr.servlet.SolrDi spatchFilter.doFilter(SolrDispatchFilter.java:323)\r\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1634)\r\n\tat org.eclipse.jetty.servlet。 ServletHandler.doHa ndle(ServletHandler.java:533)\r\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146)\r\n\tat org.eclipse.jetty.security.SecurityHandler。句柄(SecurityHandler.java:548)\ r\n\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)\r\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257 )\r\n\tat org.eclipse.je tty.server.session.SessionHandler.doHandle(SessionHandler.java:1595)\r\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)\r\n\tat org. eclipse.jetty.server.handler。 ContextHandler.doHandle(ContextHandler.java:1317)\r\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)\r\n\tat org.eclipse.jetty.servlet。 ServletHandler.doScope(Serv letHandler.java:473)\r\n\tat org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564)\r\n\tat org.eclipse.jetty.server.handler.ScopedHandler。下一个作用域(ScopedHandler.java:201)\ r\n\tat org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1219)\r\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144 )\r\n\tat org.eclipse.jett y.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:219)\r\n\tat org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126)\r\n\tat org.日食.je tty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)\r\n\tat org.eclipse.jetty.rewrite.handler.RewriteHandler.handle(RewriteHandler.java:335)\r\n\tat org. eclipse.jetty.server.handler.Hand lerWrapper.handle(HandlerWrapper.java:132)\r\n\tat org.eclipse.jetty.server.Server.handle(Server.java:531)\r\n\tat org.eclipse.jetty.server.HttpChannel。句柄(HttpChannel.java:352)\r\n\tat org.eclipse .jetty.server.HttpConnection.onFillable(HttpConnection.java:260)\r\n\tat org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:281)\r\n\tat org.eclipse .jetty.io.FillIn terest.fillable(FillInterest.java:102)\r\n\tat org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)\r\n\tat org.eclipse.jetty.util.thread .strategy.EatWhatYouKill.runTask(EatWhatYouKill .java:333)\r\n\tat org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)\r\n\tat org.eclipse.jetty.util.thread.strategy .EatWhatYouKill.tryProduce(EatWhatYouKill.java :168)\r\n\tat org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126)\r\n\tat org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread .run(ReservedThreadExecutor。 java:366)\r\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:762)\r\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool$2.run (QueuedThreadPool.java:680)\r\n\tat java。 lang.Thread.run(未知来源)\r\n", “代码”:500}}

我知道关于这个问题有很多类似的问答,但它们并不完全相同,而且我尝试过的解决方案都没有解决我的问题。

【问题讨论】:

    标签: windows curl solr


    【解决方案1】:

    我用双引号替换了单引号,并用反斜杠转义了花括号内的双引号,它已经工作了。

    我是从这里出发的:

    curl --X POST -H 'Content-type:application/json' --data-binary '{"add-field": {"name":"name", "type":"text_general", "multiValued":false, "stored":true}}' http://localhost:8983/solr/films/schema
    

    到这里:

    curl --X POST -H "Content-type:application/json" --data-binary "{\"add-field\": {\"name\":\"name\", \"type\":\"text_general\", \"multiValued\":false, \"stored\":true}}" http://localhost:8983/solr/films/schema
    

    感谢大家的集体回答。我确信将JSON 添加到单独的文件中可能有一些好处,但我想避免创建其他文件。

    【讨论】:

      【解决方案2】:

      Windows 命令提示符不支持单引号。这是一个问题,因为 cURL 语句使用单引号来指定 JSON 数据。

      要解决此问题,请将 JSON 保存在单独的文件中(例如 add-field.txt)并将其导入 cURL 语句,以便稍后您可以像这样运行它:

      curl -X POST -H 'Content-type:application/json' --data-binary @add-field.txt http://localhost:8983/solr/films/schema
      

      【讨论】:

      • 这对我来说是最好的解决方案。我陷入了转义引号,括号,大括号等的兔子洞,直到命令难以辨认。将它放在一个单独的文件中可以恢复清晰度,并具有额外的好处,您可以拆分多行并缩进。我使用了“--data”。
      【解决方案3】:

      我会走另一条路。如果你安装了微软的wonderfool工具WSL。您将能够按原样运行所有这些命令,因为您将在 linux 系统中运行。最终会大大节省时间。

      【讨论】:

        【解决方案4】:

        Gitbash 为我解决了这个问题。 WSL 崩溃的原因我目前忽略了。

        【讨论】:

          【解决方案5】:

          您可能发送的请求 json 数据中没有转义字符。因此,如果您在请求中使用了任何双引号 ("),那么您可以使用反斜杠 (\) 对其进行转义。

          更改以下内容

          curl --X POST -H 'Content-type:application/json' --data-binary '{"add-field": {"name":"name", "type":"text_general", "multiValued":false, "stored":true}}' http://localhost:8983/solr/films/schema
          

          到

          curl --X POST -H "Content-type:application/json" --data-binary "{\"add-field\": {\"name\":\"name\", \"type\":\"text_general\", \"multiValued\":false, \"stored\":true}}" http://localhost:8983/solr/films/schema
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2023-03-23
            • 2014-11-20
            • 2018-03-06
            • 1970-01-01
            • 2012-01-27
            • 1970-01-01
            • 2016-08-26
            • 2011-11-25
            相关资源
            最近更新 更多