Linux系统怎样模拟Http的get或post请求

2024-05-13

1. Linux系统怎样模拟Http的get或post请求

一、get请求:
1、使用curl命令:
curl “http://www.baidu.com” 如果这里的URL指向的是一个文件或者一幅图都可以直接下载到本地
curl -i “http://www.baidu.com” 显示全部信息
curl -l “http://www.baidu.com” 只显示头部信息
curl -v “http://www.baidu.com” 显示get请求全过程解析
2、使用wget命令:
wget “http://www.baidu.com”也可以
二、post请求
1、使用curl命令(通过-d参数,把访问参数放在里面):
curl -d “param1=value1¶m2=value2” “http://www.baidu.com”
2、使用wget命令:(--post-data参数来实现)
wget --post-data ‘user=foo&password=bar’ http://www.baidu.com
以上就是Linux模拟Http的get或post请求的方法了,这样一来Linux系统也能向远程服务器发送消息了。

Linux系统怎样模拟Http的get或post请求

2. 使用什么方法可以模拟http请求

下载集成环境
网上好多  推荐
apmserv5.2.6

3. 如何简单的模拟发送http post请求

般post应该用urlquerystring传数据吧post应该建立连接用req.write写数据

如何简单的模拟发送http post请求

4. 怎么用java模拟http请求

/*
* 得到返回的内容
*/
public static String getResult(String urlStr, String content) {
URL url = null;
HttpURLConnection connection = null;

try {
url = new URL(urlStr);
connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setUseCaches(false);
connection.connect();

DataOutputStream out = new DataOutputStream(connection.getOutputStream());
out.writeBytes(content);
out.flush();
out.close();

BufferedReader reader = new BufferedReader(new InputStreamReader(connection
.getInputStream(), "utf-8"));
StringBuffer buffer = new StringBuffer();
String line = "";
while ((line = reader.readLine()) != null) {
buffer.append(line);
}
reader.close();
return buffer.toString();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (connection != null) {
connection.disconnect();
}
}
return null;
}
追问:
没注释吗?
追答:
/*
* 得到返回的内容
*/
public static String getResult(String urlStr, String content) {
URL url = null;
HttpURLConnection connection = null;
try {
url = new URL(urlStr);
connection = (HttpURLConnection) url.openConnection();//新建连接实例
connection.setDoOutput(true);//是否打开输出流 true|false
connection.setDoInput(true);//是否打开输入流true|false
connection.setRequestMethod("POST");//提交方法POST|GET
connection.setUseCaches(false);//是否缓存true|false
connection.connect();//打开连接端口
DataOutputStream out = new DataOutputStream(connection.getOutputStream());//打开输出流往对端服务器写数据
out.writeBytes(content);//写数据,也就是提交你的表单 name=xxx&pwd=xxx
out.flush();//刷新
out.close();//关闭输出流
BufferedReader reader = new BufferedReader(new InputStreamReader(connection
.getInputStream(), "utf-8"));//往对端写完数据 对端服务器返回数据 ,以BufferedReader流来读取
StringBuffer buffer = new StringBuffer();
String line = "";
while ((line = reader.readLine()) != null) {
buffer.append(line);
}
reader.close();
return buffer.toString();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (connection != null) {
connection.disconnect();//关闭连接
}
}
return null;
}

5. 如何模拟http提交数据,GET和POST方式

Http之Get/Post请求区别 1.HTTP请求格式: 

 

 

 

[] 

在HTTP请求中,第一行必须是一个请求行(request line),用来说明请求类型、要访问的资源以及使用的HTTP版本。紧接着是一个首部(header)小节,用来说明服务器要使用的附加信息。在首部之后是一个空行,再此之后可以添加任意的其他数据[称之为主体(body)]。 

1. get是从服务器上获取数据,post是向服务器传送数据。
get 和 post只是一种传递数据的方式,get也可以把数据传到服务器,他们的本质都是发送请求和接收结果。只是组织格式和数据量上面有差别,http协议里面有介绍
  2. get是把参数数据队列加到提交表单的ACTION属性所指的URL中,值和表单内各个字段一一对应,在URL中可以看到。post是通过HTTP post机制,将表单内各个字段与其内容放置在HTML HEADER内一起传送到ACTION属性所指的URL地址。用户看不到这个过程。
因为get设计成传输小数据,而且最好是不修改服务器的数据,所以浏览器一般都在地址栏里面可以看到,但post一般都用来传递大数据,或比较隐私的数据,所以在地址栏看不到,能不能看到不是协议规定,是浏览器规定的。

如何模拟http提交数据,GET和POST方式

6. 如何使用java模拟post请求

/**     * 向指定 URL 发送POST方法的请求     *      * @param url     *            发送请求的 URL     * @param param     *            请求参数,请求参数应该是 name1=value1&name2=value2 的形式。     * @return 所代表远程资源的响应结果     */    public static String sendPost(String url, String param) {        PrintWriter out = null;        BufferedReader in = null;        String result = "";        try {            URL realUrl = new URL(url);            // 打开和URL之间的连接            URLConnection conn = realUrl.openConnection();            // 设置通用的请求属性            conn.setRequestProperty("accept", "*/*");            conn.setRequestProperty("connection", "Keep-Alive");            conn.setRequestProperty("user-agent",                    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");            // 发送POST请求必须设置如下两行            conn.setDoOutput(true);            conn.setDoInput(true);            // 获取URLConnection对象对应的输出流            out = new PrintWriter(conn.getOutputStream());            // 发送请求参数            out.print(param);            // flush输出流的缓冲            out.flush();            // 定义BufferedReader输入流来读取URL的响应            in = new BufferedReader(                    new InputStreamReader(conn.getInputStream()));            String line;            while ((line = in.readLine()) != null) {                result += line;            }        } catch (Exception e) {            System.out.println("发送 POST 请求出现异常!"+e);            e.printStackTrace();        }        //使用finally块来关闭输出流、输入流        finally{            try{                if(out!=null){                    out.close();                }                if(in!=null){                    in.close();                }            }            catch(IOException ex){                ex.printStackTrace();            }        }        return result;    }

7. C#怎么用Socket模拟 HTTP请求

已经存在webHttpRequest/WebRequest类实现web的请求,也存在WebClient等浏览器的模拟,还有轻量级的HttpClient,为什么要使用Socket模拟http请求?
如果只是出于学习的目的,那么使用reflector反射以上几个类可以直接学习的,如果是追求性能,其实httpClient的性能足够,如果是定制请求的verb,除WebClient均支持,想不起来为什么你非要使用socket模拟请求需求。
其实以上几个都是基本socket的,但是webhttpRequest是基于HttpRequest的基础类,该类的目的是实现可插入协议的开发,本身实现有FTP等几个协议;如果对于扩展协议的开发可以考虑该层。
如果你只是想学习或验证http1.1/2.0的协议,那么你直接使用filder进行构造即可验证,可然使用telnet客户端进行构造也行,只不过会麻烦一些而已。
但不管你是何目的,如果使用socket进行http请求,直接了解http协议即可。

C#怎么用Socket模拟 HTTP请求

8. shell脚本实现执行http的一个post或者get方法是怎么实现的吖?

你好,可以通过curl和wget两个命令发送http请求:
一、get请求:
1、使用curl命令:
curl “http://www.baidu.com” 如果这里的URL指向的是一个文件或者一幅图都可以直接下载到本地
curl -i “http://www.baidu.com” 显示全部信息
curl -l “http://www.baidu.com” 只显示头部信息
curl -v “http://www.baidu.com” 显示get请求全过程解析
2、使用wget命令:
wget “http://www.baidu.com”也可以

二、post请求
1、使用curl命令(通过-d参数,把访问参数放在里面):
curl -d “param1=value1¶m2=value2” “http://www.baidu.com”
2、使用wget命令:(--post-data参数来实现)
wget --post-data ‘user=foo&password=bar’ http://www.baidu.com
以上就是Linux模拟Http的get或post请求的方法了,这样一来Linux系统也能向远程服务器发送消息了。  

示例:wget --post-data=""  http://mcs-inner.99bill.com/mcs-gateway/mcs/task/clear

三、curl (可直接发送格式化请求例如json)
示例:目标url:http://fsc-inner.99bill.com/acs/deposit/{srcRef}
命令:curl -H "Content-type: application/json" -X POST -d '{"srcRef":"1002"}'http://fsc-inner.99bill.com/acs/deposit/1002