1
在客戶端,以下的Android代碼將撥打電話到本地服務器:在Python中等效的Servlet嗎?
String link = "http://localhost:8080/test/cgi-bin/test.py";
URL url = null;
try {
url = new URL(link);
HttpURLConnection client = (HttpURLConnection) url.openConnection();
JSONObject jo = new JSONObject();
jo.put("desc","xyz");
String data2 = jo.toString();
client.setRequestMethod("Post");
// client.setRequestProperty("key","value");
client.setDoOutput(true);
OutputStreamWriter outputPost = new OutputStreamWriter(client.getOutputStream());
outputPost.write(data2);
outputPost.flush();
outputPost.close();
早些時候,我使用servlet與DB作爲下面的代碼進行交互: 使用HttpServlet類,我能得到請求,它的參數:
public class ServletXYZ extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String method = request.getParameter("method");
python有沒有什麼辦法可以讓我做同樣的事情(從請求中獲取參數值)?
謝謝。
我開始與cherrypy,你會知道在哪裏把我的.py文件,其中包含處理請求和發送的響應。因此,我需要通過什麼url作爲鏈接在客戶端 – user3820753
我的意思是,我在本地使用的Apache服務器的某些目錄 – user3820753