Python запрашивает данные публикации и потокаPython

Программы на Python
Anonymous
Python запрашивает данные публикации и потока

Сообщение Anonymous »

У меня есть код для преобразования в Python, у кого-нибудь есть идеи, как это сделать?

Код: Выделить всё

// 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

Вернуться в «Python»