【问题标题】:Android URLConnection POST instead of GETAndroid URLConnection POST 而不是 GET
【发布时间】:2013-07-12 03:40:03
【问题描述】:

我有一个应用程序需要向 URL 发布多个值,并返回 XML 响应以便对其进行解析。目前,请求正在通过 URL 发送值。下面是我当前的工作代码,但我无法在 android 开发者网站上找到任何关于 POST with URLConnection 的信息。可能吗?有什么例子吗?提前感谢您的帮助!

          String url = "http://www.mywebsite.com/xml/page.cfm";
          StringBuilder sb = new StringBuilder(url);
          sb.append("?id=" + id);
          URLConnection conn = new URL(sb.toString()).openConnection();
          conn.setConnectTimeout(30000);
          conn.setReadTimeout(30000);
          SAXParserFactory spf = SAXParserFactory.newInstance();
          SAXParser sp = spf.newSAXParser();
          XMLReader xr = sp.getXMLReader();
          XMLDataHandler h = new XMLDataHandler();
          xr.setContentHandler(h);
          xr.parse(new InputSource(conn.getInputStream()));
          XMLData = XMLDataHandler.XMLData;

【问题讨论】:

    标签: android http-post


    【解决方案1】:

    看起来您应该使用 HttpURLConnection。 这篇文章可能对您有所帮助:

    How to add parameters to HttpURLConnection using POST

    【讨论】:

    • 我希望有一个使用 URLConnection 的方法,但是如果我需要切换,那么我需要切换它。谢谢你jujujuijk!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-30
    • 2011-08-04
    • 2010-09-07
    • 2021-12-18
    • 2012-03-09
    • 1970-01-01
    相关资源
    最近更新 更多