【问题标题】:How to post a json for a particular parameter using CURL如何使用 CURL 为特定参数发布 json
【发布时间】:2014-12-02 06:17:32
【问题描述】:

我尝试执行一个包含多个参数的 POST 请求。一个参数需要一个 JSON 文件。我尝试了几个选项,但我面临 json 的问题。需要json的参数是'swagger'.. 这是我尝试的 curl 请求。[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 在 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 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

【问题讨论】:

    标签: json curl


    【解决方案1】:

    您在末尾添加的参数不应包含空格。但是,如果您删除此空间,则将添加“@swagger.json”作为测试(而不是文件内容)。如果要将 JSON 作为参数传递,则可以添加到文件参数名称中,例如: 招摇={..}

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

    【讨论】:

    • $SERVER -- 你能发布它的价值吗
    • //SERVER=localhost:9763 // ,我使用 MAC。我尝试了简单的 curl 请求并尝试使用 tcpmon,//curl localhost:6666/ -H "Content-type:application/json" -X POST -d @swaggerimpl.json 在 mac 中拦截 -d 是否正常工作;// 但我在 tcpmon 窗口中看不到任何消息正文
    • 如果你使用 -vX 那么它将显示请求信息。你能发帖吗? “卷曲-vX POST ...”
    • 我已经更新了回复。尝试将 parameterName= 添加到文件中
    • 谢谢你的作品..现在一个问题;它读取我的 json,但我的后端抛出此错误;//org.mozilla.javascript.NativeJavaArray 无法转换为 java.lang.String//。我的 json 有一些数组和所有..我无法控制编辑我的 javasctript 代码..有没有办法解决这个问题?
    猜你喜欢
    • 2015-05-05
    • 2015-09-27
    • 2012-06-20
    相关资源
    最近更新 更多