我希望我的代码将“请求 url”作为输入,并将输出作为“响应 XML”。这是我想用python来实现的。我不知道如何,因为我是 python 新手。虽然我知道如何在 Java 中做到这一点,并且为此我已经用 Java 开发了代码。因此,如果有人可以帮助我解决这个问题。
Java代码片段:
import java.net.*; // import java packages.
import java.io.*;
import java.net.URL;
public class API {
public static void main(String[] args) throws Exception {
URL API = new URL("http:server//"); // Create a URL object 'API' that will locate the resources on remote server via HTTP protocol.
URLConnection request = API.openConnection(); // Retrieve a URLConnection object 'request' that will establish http connection by using openConnection() method.
BufferedReader in = new BufferedReader(new InputStreamReader(
request.getInputStream())); // Create an Output stream ‘in’ that will call InputStreamReader to read the contents of the resources.
String response;
while ((response = in.readLine()) != null) // Write to Output stream until null.
System.out.println(response); // prints the response on Console.
in.close(); // Close Output stream.
}
}