입력 매개 변수를 사용하는 아래 URL에 노출되는 ASP.net API가 있습니다. softwareProductBuildID
다음과 같이 실행됩니다. http://company.com/api/SoftwareProduct/GetSanityResults?softwareProductBuildID=CI_MSM1234.LA.1.0.0.12-00491-INT-66
API URL
: http://company.com/api/SoftwareProduct/GetSanityResults INPUT PARAMETER
: softwareProductBuildID (예 : CI_MSM1234.LA.1.0.0.12-00491-INT-66)
나는 봤고 나는 아래와 같은 것을 만들 수있는 지점에 도달 할 수 있었지만 작동하지 않습니다. 제 질문은 파이썬을 사용하여 API에 입력 매개 변수를 보내는 방법입니까? XML이 필요한 것 같지 않습니다.이 문제를 해결하는 방법은 무엇입니까?
import requests
with open("HK.xml") as f:
body = f.read()
headers = {'Content-Type': 'application/json'}
response = requests.post(
'http://company.com/api/SoftwareProduct/GetSanityResults', data=body, headers=headers)
print "Printing DEV Pool Response\n"
print response
print "Done...Printing Dev Pool Response\n"
print response.ok
print response.content
POST API 호출 :
'''
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \
"PropagationSIInfo": [ \
{ \
"MainlineSI": "string", \
"DerivateSI": "string" \
}, \
{ \
"MainlineSI": "string", \
"DerivateSI": "string" \
} \
], \
"username": "string", \
"IsDelete": true \
}' 'http://company.com/api/SoftwareProduct/PropogationRules'
'''
업데이트 된 코드 :-
import requests
import json
jsonData = '''{
"PropagationSIInfo": [
{
"MainlineSI": "string",
"DerivateSI": "string"
},
{
"MainlineSI": "string",
"DerivateSI": "string"
}
],
"username": "string",
"IsDelete": True
})'''
jsonToPython = json.loads(jsonData)
response = requests.post("http://company.com/api/SoftwareProduct/PropogationRules", json=jsonData)
print "Printing API Response\n"
print response
print "Done...Printing API Response\n"
print response.ok
print response.content
http://company.com/api/SoftwareProduct/GetSanityResults?softwareProductBuildID=CI_MSM1234.LA.1.0.0.12-00491-INT-66
맞다 면 당신이 원한다고 생각합니다.
response = requests.get(
"http://company.com/api/SoftwareProduct/GetSanityResults",
params={
"softwareProductBuildID": "CI_MSM1234.LA.1.0.0.12-00491-INT-66"
}
)
params
키워드 인수는와 요청에 쿼리 매개 변수를 추가하는 방법입니다 requests
라이브러리입니다.
편집하다
귀하의 POST
요청은 다음과 같습니다.
response = requests.post("http://company.com/api/SoftwareProduct/PropogationRules", json={
"PropagationSIInfo": [
{
"MainlineSI": "string",
"DerivateSI": "string"
},
{
"MainlineSI": "string",
"DerivateSI": "string"
}
],
"username": "string",
"IsDelete": True
})
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다