我想使用 HTTPie 或 Postman 将 Akamai FastPurge API 的请求剪在一起,这样我就可以将结构和 HTTP 请求视为一个整体,目的是构建一个构建相同 HTTP 请求的 Java 模块。
我尝试了 Akamai* 提供的多个教程,但似乎没有任何效果。 FastPurge API 的凭据位于它们自己的边缘网格文件中,我按照 Akamai 的建议编辑了 HTTPie 的 config.json。 无论使用CP代码还是URL,结果都是一样的。 API 具有读写授权,并且凭据已从文件中正确读取。
我也尝试使用Postman,但是Postman没有集成边缘网格授权,所以我必须在不知道它的外观的情况下手动完成。有一个关于如何在 Postman 中设置 Akamai API 的教程,但它缺少预请求脚本的关键部分。
*: https://developer.akamai.com/akamai-101-basics-purging , https://community.akamai.com/customers/s/article/Exploring-Akamai-OPEN-APIs-from-the-command-line-using-HTTPie-and-jq?language=en_US , https://developer.akamai.com/api/core_features/fast_purge/v3.html , https://api.ccu.akamai.com/ccu/v2/docs/index.html **: https://community.akamai.com/customers/s/article/Using-Postman-to-access-Akamai-OPEN-APIs?language=en_US
我在HTTPie中收到的错误是这样的:
C:python>http --auth-type=edgegrid -a default: :/ccu/v3/invalidate/url/production objects:='["https://www.example.com","http://www.example.com"]' --debug
HTTPie 1.0.3-dev
Requests 2.21.0
Pygments 2.3.1
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 22:20:52) [MSC v.1916 32 bit (Intel)]
c:pythonpython.exe
Windows 10
<Environment {
"colors": 256,
"config": {
"__meta__": {
"about": "HTTPie configuration file",
"help": "https://httpie.org/doc#config",
"httpie": "1.0.3-dev"
},
"default_options": "['--verbose', '--traceback', '--auth-type=edgegrid', '--print=Hhb', '--timeout=300', '--style=autumn', '-adefault:']"
},
"config_dir": "%home",
"is_windows": true,
"stderr": "<colorama.ansitowin32.StreamWrapper object at 0x066D1A70>",
"stderr_isatty": true,
"stdin": "<_io.TextIOWrapper name='<stdin>' mode='r' encoding='utf-8'>",
"stdin_encoding": "utf-8",
"stdin_isatty": true,
"stdout": "<colorama.ansitowin32.StreamWrapper object at 0x066D19D0>",
"stdout_encoding": "utf-8",
"stdout_isatty": true
}>
Traceback (most recent call last):
File "c:pythonlibsite-packageshttpieinput.py", line 737, in parse_items
value = load_json_preserve_order(value)
File "c:pythonlibsite-packageshttpieutils.py", line 7, in load_json_preserve_order
return json.loads(s, object_pairs_hook=OrderedDict)
File "c:pythonlibjson__init__.py", line 361, in loads
return cls(**kw).decode(s)
File "c:pythonlibjsondecoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "c:pythonlibjsondecoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:PythonScriptshttp-script.py", line 11, in <module>
load_entry_point('httpie==1.0.3.dev0', 'console_scripts', 'http')()
File "c:pythonlibsite-packageshttpie__main__.py", line 11, in main
sys.exit(main())
File "c:pythonlibsite-packageshttpiecore.py", line 210, in main
parsed_args = parser.parse_args(args=args, env=env)
File "c:pythonlibsite-packageshttpieinput.py", line 152, in parse_args
self._parse_items()
File "c:pythonlibsite-packageshttpieinput.py", line 358, in _parse_items
data_class=ParamsDict if self.args.form else OrderedDict
File "c:pythonlibsite-packageshttpieinput.py", line 739, in parse_items
raise ParseError('"%s": %s' % (item.orig, e))
httpie.input.ParseError: "objects:='[https://www.example.com,http://www.example.com]'": Expecting value: line 1 column 1 (char 0)
或者:
C:python>http POST --auth-type=edgegrid -a default: :/ccu/v3/invalidate/cpcode/production < file.json
usage: http [--json] [--form] [--pretty {all,colors,format,none}]
[--style STYLE] [--print WHAT] [--headers] [--body] [--verbose]
[--all] [--history-print WHAT] [--stream] [--output FILE]
[--download] [--continue]
[--session SESSION_NAME_OR_PATH | --session-read-only SESSION_NAME_OR_PATH]
[--auth USER[:PASS]] [--auth-type {basic,digest,edgegrid}]
[--proxy PROTOCOL:PROXY_URL] [--follow]
[--max-redirects MAX_REDIRECTS] [--timeout SECONDS]
[--check-status] [--verify VERIFY]
[--ssl {ssl2.3,tls1,tls1.1,tls1.2}] [--cert CERT]
[--cert-key CERT_KEY] [--ignore-stdin] [--help] [--version]
[--traceback] [--default-scheme DEFAULT_SCHEME] [--debug]
[METHOD] URL [REQUEST_ITEM [REQUEST_ITEM ...]]
http: error: unrecognized arguments: :/ccu/v3/invalidate/cpcode/production
典型的成功响应如下所示:
{
"httpStatus" : 201,
"detail" : "Request accepted.",
"estimatedSeconds" : 420,
"purgeId" : "95b5a092-043f-4af0-843f-aaf0043faaf0",
"progressUri" : "/ccu/v2/purges/95b5a092-043f-4af0-843f-aaf0043faaf0",
"pingAfterSeconds" : 420,
"supportId" : "17PY1321286429616716-211907680"
}
如果有人能帮助我更正我在 HTTPie 或 Postman 上的设置,或者给我 Akamai FastPurge HTTP 请求的完整结构,这样我就可以跳过 HTTPie 或 Postman 的麻烦,我将不胜感激。
非常感谢,非常感谢您的帮助!
Postman 现在具有 Akamai edgeGrid 授权类型。 它获取您的 .edgerc 文件的内容。
我在集合上设置了它,并让所有调用继承授权。