Python到Php使用http请求发布数据

2024-09-30 01:26:03 发布

您现在位置:Python中文网/ 问答频道 /正文

import requests
req = requests.post('http://example.in/phppage.php', data = {'device_id':220,'tank_type':1,'level_pct':78,'water_flow':0,'water_over_flow':0})
print("HTTP Connection Status::"+str(req.status_code))

当我运行此代码时,它显示http连接状态404。怎么了?你知道吗


Tags: inimportidhttpdataexampledeviceflow
1条回答
网友
1楼 · 发布于 2024-09-30 01:26:03
# importing the requests library
import requests

# defining the api-endpoint 
API_ENDPOINT = "http://pastebin.com/api/api_post.php"

# your API key here
API_KEY = "XXXXXXXXXXXXXXXXX"

# your source code here
source_code = '''
print("Hello, world!")
a = 1
b = 2
print(a + b)
'''

# data to be sent to api
data = {'api_dev_key':API_KEY,
        'api_option':'paste',
        'api_paste_code':source_code,
        'api_paste_format':'python'}

# sending post request and saving response as response object
r = requests.post(url = API_ENDPOINT, data = data)

# extracting response text `enter code here`
pastebin_url = r.text
print("The pastebin URL is:%s"%pastebin_url)

相关问题 更多 >

    热门问题