如何使用CURL为特定参数发布json

时间:2014-12-02 06:17:32

标签: json curl

我尝试执行包含多个参数的POST请求。一个参数需要一个JSON文件。我尝试了几个选项,但我面临着json的问题。需要json的参数是'swagger' .. 这是我尝试的卷曲请求。[1]但看起来服务器不接受这个。我得到了以下错误;

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

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

[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 -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;

错误;     在java.lang.Thread.run(Thread.java:695) 引起:java.lang.ClassCastException:org.mozilla.javascript.NativeJavaArray无法强制转换为java.lang.String     在     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

可疑的json文件

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

1 个答案:

答案 0 :(得分:1)

您在末尾添加的参数不应包含空格。但是如果删除这个空格,那么'@ swagger.json'将被添加为测试(不是文件内容)。如果要将JSON作为参数传递,则可以添加到文件参数名称,如: 昂首阔步= {..}

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