【发布时间】:2020-01-10 09:10:12
【问题描述】:
我在 python 上有很多设置的 POST 请求,但我不明白它们在 curl 中的样子。
data_str = '{' + '"username": "{}", "domain_id": {}, "password": {}'.format(login, domain_id, password) + '}'
try:
data = requests.post("https://example.com/v/session",
proxies=proxy,
verify=False,
data=data_str,
headers={"Content-Type": "application/json;charset=UTF-8",
"Accept": "application/json"})
if is_json(data.text):
print(data)
我发现 url 设置参数 CURLOPT_URL,标题 - CURLOPT_HTTPHEADER。但是如何设置代理、验证、数据?如何在 python 中获取 json? 如何完成与python中结果相同的代码:
CURL *curl = curl_easy_init();
struct curl_slist *list = NULL;
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
list = curl_slist_append(list, "Shoesize: 10");
list = curl_slist_append(list, "Accept:");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
curl_easy_perform(curl);
curl_slist_free_all(list); /* free the list again */
}
【问题讨论】:
标签: c++ curl python-requests http-post