windows 在POST中转义JSON数据

cgh8pdjw  于 2023-06-07  发布在  Windows
关注(0)|答案(2)|浏览(170)

我正在努力POSTJSON到我的本地主机,使用Curl从**mingw64**。

curl -H 'Content-Type: application/csp-report;charset=utf-8' 
--data '{"csp-report":{"document-uri":"https://localhost/test",
"referrer":"https://www.google.com/",
"violated-directive":"default-src self","original-policy":"default-src self; report-uri /csp.php",
"blocked-uri":"http://evilhackerscripts.com"}}' 
'https://localhost/csp.php'

测试一些在线建议的转义,得到以下输出:

curl: (6) Could not resolve host: "referrer"
curl: (3) URL using bad/illegal format or missing URL
curl: (6) Could not resolve host: "https
curl: (6) Could not resolve host: "violated-directive"
curl: (3) URL using bad/illegal format or missing URL
curl: (6) Could not resolve host: "default-src
curl: (6) Could not resolve host: self",
curl: (6) Could not resolve host: "original-policy"
curl: (3) URL using bad/illegal format or missing URL
curl: (6) Could not resolve host: "default-src
curl: (6) Could not resolve host: self;
curl: (6) Could not resolve host: report-uri
curl: (3) URL using bad/illegal format or missing URL
curl: (6) Could not resolve host: ,"blocked-uri"
curl: (3) URL using bad/illegal format or missing URL
curl: (3) unmatched close brace/bracket in URL position 21:

错误:这也是之前出现的问题。可以从POSTMAN进行POST,但不能通过mingw 64在Windows命令提示符下使用curl
注意:尝试获取
C:\www\testing\csp.php
11行非对象的属性'csp-report'
注意:尝试获取C:\www\testing\csp.php11行的非对象属性'document-uri'
注意:尝试获取C:\www\testing\csp.php12行非对象的属性'csp-report'
注意C:\www\testing\csp.php12行,尝试获取非对象的属性'referrer'
注意:尝试获取C:\www\testing\csp.php13行非对象的属性'csp-report'
注意事项C:\www\testing\csp-reporter.php13行尝试获取非对象的属性'violated-directive'
注意:尝试获取C:\www\testing\csp.php14行非对象的属性'csp-report'
注意C:\www\testing\csp.php14行尝试获取非对象的属性'original-policy'
注意:尝试获取C:\www\testing\csp.php15行非对象的属性'csp-report'
注意:尝试获取C:\www\testing\csp.php15行的非对象属性'blocked-uri'

myzjeezk

myzjeezk1#

也许你应该像这样在单行中运行curl命令:

curl -H 'Content-Type: application/csp-report;charset=utf-8' --data '{"csp-report":{"document-uri":"https://localhost/test", "referrer":"https://www.google.com/", "violated-directive":"default-src self","original-policy":"default-src self; report-uri /csp.php", "blocked-uri":"http://evilhackerscripts.com"}}' 'https://localhost/csp.php'

或者,你可以在每一行后面添加一个反斜杠,告诉shell你的命令还没有结束:

curl -H 'Content-Type: application/csp-report;charset=utf-8' \
--data '{"csp-report":{"document-uri":"https://localhost/test",
"referrer":"https://www.google.com/",
"violated-directive":"default-src self","original-policy":"default-src self; 
report-uri /csp.php",
"blocked-uri":"http://evilhackerscripts.com"}}' \
'https://localhost/csp.php'

希望能帮到你。

gz5pxeao

gz5pxeao2#

这个名为post.sh的小脚本为我工作:

#! /bin/bash

US01='bar2'$1'@foo.com'
RE01='{"email":"'${US01}'","password":"111-111"}'

curl -v -H "Content-Type: application/json" \
  -d ${RE01} \
  http://localhost:30025/signup

这样称呼它:

./post.sh 51

传入一个新号码会在服务器上创建一个新用户。
样品运行:

./post.sh 51
{"email":"bar251@foo.com","password":"111-111"}
*   Trying 127.0.0.1:30025...
* Connected to localhost (127.0.0.1) port 30025 (#0)
> POST /signup HTTP/1.1
> Host: localhost:30025
> User-Agent: curl/7.81.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 47
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< X-Powered-By: Express
< Content-Type: application/json; charset=utf-8
< Content-Length: 353
< ETag: W/"161-S6X2031k1pG3b1BJRvOfoUtgcW0"
< Date: Sun, 04 Jun 2023 17:33:15 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
<
* Connection #0 to host localhost left intact 
{
    "uid":"baN8CUel91SAbno4h6qWudA4qIR2","email":"bar251@foo.com",
    "emailVerified":false,"disabled":false,
    "metadata": {
        "lastSignInTime":null,"creationTime":"Sun, 04 Jun 2023 17:33:15 GMT",
        "lastRefreshTime":null
    },
    "tokensValidAfterTime":"Sun, 04 Jun 2023 17:33:15 GMT",
    "providerData":[{
        "uid":"bar251@foo.com",
        "email":"bar251@foo.com",
        "providerId":"password"
    }]
}

相关问题