如何判断我的HTTP请求成功还是失败?

时间:2020-07-20 20:08:16

标签: http curl post

假设您有一种使用单选按钮和标准“提交”按钮提交的表单。我希望能够不使用网站而是使用cURL从命令行提交对表单的回复。

当我在浏览器中提交表单并检查网络流量时,以下是我看到的重要详细信息:

URL(示例):www.example.com/folder/ajax.php

数据:{JSON内容的大字符串}

这是我正在尝试的curl调用:

curl -X POST -H "Content-Type: application/json" -L -d '{big string of json stuff}' http://www.example.com/folder/ajax.php --verbose

我遇到的问题是我的请求实际上没有做任何事情,也就是说,提交表单后,我没有看到期望的网站上的更改。帮助吗?

编辑:我可以看到我的请求失败。成功的呼叫将返回类似下面的行的内容,该行不会出现。所以问题是我的电话怎么了?

{"success":true,"data":{website specific stuff}}

以下是我打电话时得到的信息:

Note: Unnecessary use of -X or --request, POST is already inferred.
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 001.01.001.01:01...
* Connected to www.example.com (001.01.001.01) port 80 (#0)
> POST /example-admin/admin-ajax.php HTTP/1.1
> Host: www.example.com
> User-Agent: curl/7.70.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 273
>
} [273 bytes data]
* upload completely sent off: 273 out of 273 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 301 Moved Permanently
< Date: Mon, 20 Jul 2020 20:10:06 GMT
< Transfer-Encoding: chunked
< Connection: keep-alive
< Cache-Control: max-age=3600
< Expires: Mon, 20 Jul 2020 21:10:06 GMT
< Location: https://www.example.com/example.php
< cf-request-id: 040f721ebb000056c7c49ef200000001
< Server: cloudflare
< CF-RAY: 5b5f52ddff2656c7-IAD
<
* Ignoring the response-body
{ [5 bytes data]
100   273    0     0  100   273      0   1560 --:--:-- --:--:-- --:--:--  1578
* Connection #0 to host www.example.com left intact
* Issue another request to this URL: 'https://www.example.com/folder/admin-ajax.php'
* Switch from POST to GET
*   Trying 001.01.01.01:001...
* Connected to www.example.com (001.01.01.01) port 443 (#1)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
  CApath: none
} [5 bytes data]
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
} [512 bytes data]
* TLSv1.3 (IN), TLS handshake, Server hello (2):
{ [122 bytes data]
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
{ [19 bytes data]
* TLSv1.3 (IN), TLS handshake, Certificate (11):
{ [2218 bytes data]
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
{ [79 bytes data]
* TLSv1.3 (IN), TLS handshake, Finished (20):
{ [52 bytes data]
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
} [1 bytes data]
* TLSv1.3 (OUT), TLS handshake, Finished (20):
} [52 bytes data]
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use h2
* Server certificate:
*  subject: C=[location]; O=Cloudflare, Inc.; CN=sni.cloudflaressl.com
*  start date: Jul  8 00:00:00 2020 GMT
*  expire date: Jul  8 12:00:00 2021 GMT
*  subjectAltName: host "www.example.com" matched cert's "www.example.com"
*  issuer: C=US; O=Cloudflare, Inc.; CN=Cloudflare Inc ECC CA-3
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
} [5 bytes data]
* Using Stream ID: 1 (easy handle 0x2552070)
} [5 bytes data]
> POST /example.php HTTP/2
> Host: www.example.com
> user-agent: curl/7.70.0
> accept: */*
> content-type: application/json
>
{ [5 bytes data]
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
{ [230 bytes data]
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
{ [230 bytes data]
* old SSL session ID is stale, removing
{ [5 bytes data]
* Connection state changed (MAX_CONCURRENT_STREAMS == 256)!
} [5 bytes data]
  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0< HTTP/2 400
< date: Mon, 20 Jul 2020 20:10:07 GMT
< content-type: text/html; charset=UTF-8
< set-cookie: __cfduid=dbb003aa8db90cc84daebeb59f5c0f40f1595275806; expires=Wed, 19-Aug-20 20:10:06 GMT; path=/; domain=.example.com; HttpOnly; SameSite=Lax; Secure
< x-robots-tag: noindex
< expires: Wed, 11 Jan 1984 05:00:00 GMT
< cache-control: no-cache, must-revalidate, max-age=0
< vary: User-Agent,Accept-Encoding
< cf-cache-status: DYNAMIC
< cf-request-id: 040f721f0c0000c1cf91808200000001
< expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
< server: cloudflare
< cf-ray: 5b5f52de7aedc1cf-IAD
<
{ [1 bytes data]
100     1    0     1    0     0      0      0 --:--:--  0:00:01 --:--:--     30
* Connection #1 to host www.example.com left intact

0 个答案:

没有答案
相关问题