简体   繁体   English

如何将特定的 CURL 请求转换为 Python

[英]How to convert specific CURL request to Python

I have the following Curl request:我有以下 Curl 请求:

curl -v --location --request POST 'http://127.0.0.1:8080/abc' \--header 'Content-Type: application/json' \--data-raw '{data}'

I tried using pycurl and requests command.我尝试使用 pycurl 和 requests 命令。 Also tried to put headers but it was of no use.还尝试放置标题,但没有用。

My tried code:我试过的代码:

requests = "curl -v --location"

a = "http://127.0.0.1:8080/abc"

headers = {'Content-Type': 'application/json'}

r = requests.post(url=a, headers= headers , params=data)

Is this works?这行得通吗? https://curl.trillworks.com/ https://curl.trillworks.com/

import requests

headers = {
    'Content-Type': 'application/json',
}

data = '{data}'

response = requests.post('http://127.0.0.1:8080/abc',
                         headers=headers,
                         data=data)

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM