POST /example/asdfas HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Type: multipart/form-data; boundary=---------------------------241652170216373
Content-Length: 279
-----------------------------241652170216373
Content-Disposition: form-data; name="value_1"
12345
-----------------------------241652170216373
Content-Disposition: form-data; name="value_2"
67890
-----------------------------241652170216373--
requests belgeleri bu dosyalar argümanı gerektiğini düşündürmektedir Kullanılmalıdır.
aşağıdaki çağrıyı çalıştığınızda:
import requests
requests.post('http://example.com/example/asdfas', files={'value_1': '12345',
'value_2': '67890'})
alıyorum aşağıdaki HTTP isteği:
'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate, compress',
'Content-Length': '264',
'User-Agent': 'python-requests/2.2.1 CPython/3.3.2 Windows/7',
'Content-Type': 'multipart/form-data; boundary=273f13699c02429db4eb95c97f757d38'
--273f13699c02429db4eb95c97f757d38
Content-Disposition: form-data; name="value_1"; filename="value_1"
12345
--273f13699c02429db4eb95c97f757d38
Content-Disposition: form-data; name="value_2"; filename="value_2"
67890
--273f13699c02429db4eb95c97f757d38--
Ben de veri argümanı kullanmaya çalıştık:
import requests
requests.post('http://example.com/example/asdfas', data={'value_1': '12345',
'value_2': '67890'})
çıkan
: aşağıdaki HTTP isteğinde'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': '27',
'User-Agent': 'python-requests/2.2.1 CPython/3.3.2 Windows/7',
'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate, compress'
value_2=67890&value_1=12345
Yapmakta olduğum sorun, dosya argümanının kullanılması, sunucunun, HTTP isteğinde gönderilen beklenmedik "dosya adı" bilgisinden dolayı, sunucunun tanımadığı bir çağrıyla sonuçlanmasıdır. Veri argümanı kullanılarak yanlış Content-Type başlığı gönderilir. aynı ilk HTTP isteği çoğaltmak için doğru işlev çağrısı nedir -
İlk istek ben isteği göndermek istediğiniz sunucuda çalıştığı bilinmektedir? beklendiği gibi
import requests
requests.post('http://example.com/example/asdfas', files={'value_1': (None, '12345'), 'value_2': (None, '67890')})
Works:
Düzenleme:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form action="http://example.com/example/asdfas" method="post" enctype="multipart/form-data">
<label for="v1">Value 1</label>
<input id="v1" type="text" name="value_1">
<label for="v2">Value 2</label>
<input id="v2" type="text" name="value_2">
<input type="submit">
</form>
</body>
</html>
İyi bir 'form' gibi görünmüyor ... Eğer denerseniz, ne olur? 'Requests.post (' http://example.com/example/asdfas ', data = {' name ':' 12345 ' }) '? Sunucu ne yapar? – BorrajaX
Form, standart dışı olabilir. Bir çalışma isteği oluşturmak için gerekli olan HTML'yi ekledim. Sunucu, başarıda XML veya hatalarda URL bulunamamış sunucu hatası verir. – sornars