Код: Выделить всё
// Creating a request using a URL that can receive a post.
WebRequest request = WebRequest.Create("http://” + textBoxIP.Text + "/xml/printer.htm”);
// Setting the Method property of the request to POST.
request.Method = "POST”;
// Creating POST data and converting it to a byte array.
string postData = "This is a test that posts this string to a Web server.”;
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// Setting the ContentType property of the WebRequest.
request.ContentType = "text/plain”;
// Setting the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Getting the low of requests.
Stream dataStream = request.GetRequestStream();
// Writing data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
// Get the answer.
WebResponse response = request.GetResponse();
Код: Выделить всё
import requests
xml = 'This is a test that posts this string to a Web server.'
headers = {'Content-Type': 'text/plain'} # set what your server accepts
x=requests.post('http://192.168.2.194/xml/printer.htm', data=xml, headers=headers).text
print(x)
Подробнее здесь: https://stackoverflow.com/questions/785 ... tream-data