如何使用CURL为特定参数发布json [英] How to post a json for a particular parameter using CURL

查看:370
本文介绍了如何使用CURL为特定参数发布json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试做一个包含多个参数的POST请求。一个parameetr需要一个JSON文件。我试过几个选项,但我面对问题的json。需要json的参数是'swagger' ..
这是我尝试的curl请求。[1]但看起来像这不被服务器接受。我收到以下错误:

I try to do a POST request which contains number of parameters. One parameetr require a JSON file. I tried several options but i face issue with json. The parameter which requires json is 'swagger'.. Here is the curl request I try.[1] But looks like this is not accepted by server. Im getting following error;

"null is not supported"}curl: (6) Could not resolve host: swaggerimpl.json

如何使用curl为特定参数发布JSON?

How can i post the JSON using curl for a particular parameter?

[1]

curl -X POST -b  cookies $SERVER/publisher/site/blocks/item-design/ajax/add.jag -d "action=implement&name=YoutubeFeeds&visibility=public&version=1.0.0&provider=admin&endpoint_type=http&implementation_methods=http&wsdl=&wadl=&endpointType=nonsecured&production_endpoints=http://gdata.youtube.com/feeds/api/standardfeeds&implementation_methods=endpoint" -H 'Content-Type: application/json' -d 'swagger=' @swaggerimpl.json 

编辑:

Curl Command

curl -X POST -b  cookies $SERVER/publisher/site/blocks/item-design/ajax/add.jag -d "action=implement&name=YoutubeFeeds&visibility=public&version=1.0.0&provider=admin&endpoint_type=http&implementation_methods=http&wsdl=&wadl=&endpointType=nonsecured&production_endpoints=http://gdata.youtube.com/feeds/api/standardfeeds&implementation_methods=endpoint" -d @swagger_impl.json -d @endpointconfig_impl.json;

错误;
at java.lang.Thread.run (Thread.java:695)
导致:java.lang.ClassCastException:org.mozilla.javascript.NativeJavaArray不能转换为java.lang.String
at
at sun.reflect。 NativeMethodAccessorImpl.invoke0(Native方法)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

Error; at java.lang.Thread.run(Thread.java:695) Caused by: java.lang.ClassCastException: org.mozilla.javascript.NativeJavaArray cannot be cast to java.lang.String at at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

可疑的json文件

The suspect json file

swagger={
    "apiVersion": "1.0.0",
    "swaggerVersion": "1.2",
    "authorizations": {
        "oauth2": {
            "scopes": [],
            "type": "oauth2"
        }
    },
.........
}

铸造代码

public static boolean jsFunction_updateAPIImplementation(Context cx, Scriptable thisObj,
                                            Object[] args,  Function funObj) throws Exception, ScriptException {
        boolean success = false;

        if (args==null||args.length == 0) {
            handleException("Invalid number of input parameters.");
        }

        NativeObject apiData = (NativeObject) args[0]; //This cause issue


推荐答案

结束时不应该包含空格。但是如果你删除这个空间,那么'@ swagger.json'将被添加为测试(而不是文件内容)。如果你想传递JSON作为参数,你可以添加到文件参数名称如:
swagger = {..}

Parameter that you are adding at the end should not contain the space. But if you remove this space then '@swagger.json' will be added as a test (not the file content). If you want to pass JSON as a parameter then you can add to the file parameter name like: swagger={..}

看起来像解决方法,但curl将每个-d参数合并到请求参数中,并且不允许非引号空格。

It looks like workaround but curl will merge every -d parameter into the request parameters and it doesn't allow unquoted spaces.

这篇关于如何使用CURL为特定参数发布json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆