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();
    }
    }

  • 相关阅读:
    clock时钟
    Excel一对多查找
    tcl概述
    Linux命令(一)
    perl合并文件
    数字IC设计工程师的知识结构
    阿里云ECS专有网络下安装flannel注意事项
    阿里云kubernetes遭入侵pubg进程占用cpu资源100%解决方法
    JSON Web Tokens测试工具
    Linux搭建Node.js环境
  • 原文地址:https://www.cnblogs.com/yiyunkeji/p/6477877.html
Copyright © 2011-2022 走看看