저는 localhost를 사용하여 파이썬 스크립트를 테스트하고 있으며 PuTTY를 사용하는 텔넷을 통해 테스트해야합니다. 이 파이썬 스크립트가 있습니다.
@app.route('/add/', methods=['POST'])
def add_entry():
db = get_db()
db.execute('insert into entries (title, text) values (?, ?)',
("value_from_telnet", "another_value_from_telnet"))
db.commit()
print("Saved")
return "Saved"
이제 127.0.0.1/add에 연결하는 방법과 POST 메서드에 값을 넣는 방법을 모르겠습니다. 다음과 같은 연결을 사용할 수 없습니다.
$ o 127.0.0.1/add
그리고 이것을 시도하면 :
$ o 127.0.0.1
$ GET / HTTP/1.0
$ Host: 127.0.0.1/add
결과는 404 NOT FOUND입니다 (브라우저를 통해 작동하지만 정적 삽입 값 및 GET 메서드에서만). 그래서이 주소 127.0.0.1/add에 연결하고 값을 POST 메서드에 가져 와서 데이터베이스에 삽입 값으로 사용하는 방법을 묻고 싶습니다. 감사합니다
대신 curl을 사용하십시오. curl -v -X POST 'http://<ip.address.of.server>/add' --data "title=foo&text=baz and spam and eggs"
텔넷 게시물의 경우 다음과 같이 요청 본문을 지정해야합니다.
POST /add HTTP/1.1
Content-type:application/x-http-form-urlencoded
title=foo&text=baz+and+spam+and+eggs
사전에서 쿼리 문자열을 작성하려면 urllib가 필요합니다.
import urllib
params = {title:"foo",text:"baz and spam and eggs"}
print """
POST /add HTTP/1.1
Content-type:application/x-http-form-urlencoded
""",urlencode(params)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다