Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 如何使POST松弛';谁的网址?_Json_Url_Post_Curl_Slack - Fatal编程技术网

Json 如何使POST松弛';谁的网址?

Json 如何使POST松弛';谁的网址?,json,url,post,curl,slack,Json,Url,Post,Curl,Slack,我不能简单地发布到Slack的url 我需要这样的帖子: {“text”:“} 像https://something.slack.com/services/XXXXXXXX/XXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXX首先尝试使用curl命令 curl -X POST -H 'Content-type: application/json' --data '{"text":"This is a line of text.\nAnd this is another one."}'

我不能简单地发布到Slack的url

我需要这样的帖子:

{“text”:“}


https://something.slack.com/services/XXXXXXXX/XXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXX

首先尝试使用curl命令

curl -X POST -H 'Content-type: application/json' --data '{"text":"This is a line of text.\nAnd this is another one."}' https://something.slack.com/services/XXXXXXXX/XXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXX
如果它起作用的话,那就是小菜一碟

OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"text\":\"This is a line of text.\\nAnd this is another one.\"}");
Request request = new Request.Builder()
  .url("https://something.slack.com/services/XXXXXXXX/XXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXX")
  .post(body)
  .addHeader("content-type", "application/json")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();

类似这样的curl命令将起作用:

read -r -d '' PAYLOAD << EOM
{"attachments": [{
    "text": "Hello world!"
  }]
}
EOM
curl --data-urlencode "payload=$PAYLOAD" "https://something.slack.com/services/XXXXXXXX/XXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXX"

read-r-d''负载您使用的是哪种语言?如果您使用的是CURL libs,您能提供一个更完整的示例吗?不要故意破坏您的问题。这是什么语言?它是java…您想要哪种语言的解决方案。。。第一个是curl命令,第二个是它在javaLinux或windows中的等效实现??在linux中,只需将其粘贴到终端中,然后按enter键……对于windows,安装curl for windows如何执行此操作?在该站点的浏览器控制台中?一个shell控制台,例如OS X中的默认终端。
read
命令是一个内置的bash命令,默认情况下安装了
curl
。它们可能也可以在任何linux发行版上使用,但在Windows上只能靠自己。