zoukankan      html  css  js  c++  java
  • post测试

    public class TestPost {
    public static void testPost() throws IOException {
    // 访问的接口地址
    URL url = new URL(
    "http://.........");
    URLConnection connection = url.openConnection();
    connection.setDoOutput(true);
    OutputStreamWriter out = new OutputStreamWriter(
    connection.getOutputStream(), "8859_1");
    out.write("password=&name="); // 向页面传递数据。post的关键所在!

    // remember to clean up
    out.flush();
    out.close();
    /**
    * 这样就可以发送一个看起来象这样的POST: POST /jobsearch/jobsearch.cgi HTTP 1.0 ACCEPT:
    * text/plain Content-type: application/x-www-form-urlencoded
    * Content-length: 99 username=bob password=someword
    */
    // 一旦发送成功,用以下方法就可以得到服务器的回应:
    String sCurrentLine;
    String sTotalString;
    sCurrentLine = "";
    sTotalString = "";
    InputStream l_urlStream;
    l_urlStream = connection.getInputStream();
    // 传说中的三层包装阿!
    BufferedReader l_reader = new BufferedReader(new InputStreamReader(
    l_urlStream));
    while ((sCurrentLine = l_reader.readLine()) != null) {
    sTotalString += sCurrentLine + "/r/n";

    }
    System.out.println(sTotalString);
    }

    public static void main(String[] args) throws IOException {
    testPost();
    }
    }

  • 相关阅读:
    #公式与实现# Jacobi迭代 Gauss-Seidel迭代
    数据结构-C:二叉树的遍历
    c++
    Unix Systems Programming
    二进制文件读取写入(一)
    关于理论、模型与算法
    《计算机图形学与几何造型导论》读书笔记1
    petaPar培训文档
    等参元的高斯积分详解
    水平集函数具体实现
  • 原文地址:https://www.cnblogs.com/yiyunkeji/p/6477877.html
Copyright © 2011-2022 走看看