`
- 浏览:
709547 次
- 性别:
- 来自:
上海
-
httpclient get post到一个php网站
java 代码
- import java.io.IOException;
-
-
-
- import org.apache.commons.httpclient.*;
-
- import org.apache.commons.httpclient.methods.*;
-
-
- public class SimpleHttpClient {
-
-
-
- public static void main(String[] args) throws IOException
-
- {
-
- HttpClient client = new HttpClient();
-
-
-
- HttpMethod method = getGetMethod();
-
-
- client.executeMethod(method);
-
-
-
- System.out.println(method.getStatusLine());
-
-
-
- String response =
-
- new String(method.getResponseBodyAsString().getBytes("8859_1"));
-
-
-
- System.out.println(response);
-
- method.releaseConnection();
-
- }
-
-
-
-
-
-
-
-
-
- private static HttpMethod getGetMethod(){
- String path = "D:\\data\\uploaddata.txt";
- return new GetMethod("http://localhost/Simple/clientsetdata.php/clientsetdata.php?path="+path);
-
- }
-
-
-
-
-
-
-
-
-
- private static HttpMethod getPostMethod(){
-
- PostMethod post = new PostMethod("/clientsetdata.php");
-
- NameValuePair age= new NameValuePair("age","99");
-
- post.setRequestBody(new NameValuePair[] { age});
-
- return post;
-
- }
-
- }
clientsetdata.php 代码
- php
-
- //链接数据库
- $user = "root";
- $pass = "";
- $db = "sss";
- $link = mysql_connect( "localhost", $user, $pass );
-
- if ( ! $link ){
- die( "Couldn't connect to MySQL" );
- }
-
- mysql_select_db( $db, $link ) or die ( "Couldn't open $db: ".mysql_error() );
-
- $path=$_GET['path'];
- // echo "$path";
- $userfile= file_get_contents($path);
- echo $userfile;
-
-
- mysql_close( $link );
-
- ?>
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
HttpClient.php类文件,用于模拟get或post请求,源码中基本使用例子
php HttpClient类,可模拟get或post提交,文件名:HttpClient.class.php
一个HttpClient组件,可以发送HTTP POST、GET请求。 用PHP面向对象的思想实现
这是一段php封装的HttpClient类,可实现GET POST Cookie Session等简单的功能。原来做过,这两天重新修改了一下。 <?php /* * Filename: httpclient.php * Created on 2012-12-21 * Created by RobinTang * ...
GET请求 $ http = new HttpClient ();$ http -> set_header ( 'User-Agent' , 'Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20100101 Firefox/13.0.1' ); $ http -> get ( 'http://www.example.com/' ); echo $ ...
client.getState().getCookies()); if (cookies != null) if (cookies.length == 0) { System.out.println("Cookies is not Exists "); } else { for (int i = 0; i ; i++) { System.out.println(cookies[i]....
Unirest 是一个轻量级的 HTTP 请求库,可发起 GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS 请求。支持 Node、Ruby、Java、PHP、Python、Objective-C、.NET 等多种语言。底层是基于httpclient,所以使用Unirest...
Codeigniter 基本 HTTP 客户端使用 PHP cURL 简化 GET/POST 请求,目前仅支持 JSON 格式。 XML,图像功能即将推出。安装将HttpClient.php放入您的应用程序/库中用法初始化 $ this -> load -> library ( 'HttpClient'...
Unirest是一个轻量级的HTTP请求库,涵盖Node、Ruby、Java、PHP、Python、Objective-C、.NET等多种语言。可发起GET、POST、PUT、PATCH、DELETE、HEAD、OPTIONS请求。 特性 1.能够伪造GET, POST, PUT, PATCH, DELETE,...
在java工程里如果需要透传什么信息给一个http接口的话,我们往往会使用HttpClient这个类,然后set很多param参数,这个类自然是很优秀的也被很多线上工程使用着,但是使用的过程中总不是那么的简便,比如需要引很多包...
?...use Lightfly\Finance\HttpClient;use Lightfly\Finance\Stock\...高级如果不喜欢 guzzle 或者主机配置的原因,可以替换 http client 的实现,只要继承 HttpClientInterface 实现相应的 get 和 post 方法即可,示例:
$response = $httpClient->get('https://www.googleapis.com/plus/v1/people/me'); ``` ### Caching ### It is recommended to use another caching library to improve performance. This can be done by passing...
特性GET/POST/PUT/DELETE/UPDATE 等请求方式浏览器级别 Cookies 管理上传及下载请求头和响应头失败重试自动重定向HTTP 代理方式请求SSL 证书(HTTPS)并发批量请求HTTP2WebSocketCurl & Swoole 环境智能兼容连接池...
本文实例讲述了PHP封装请求类。...class HttpClient extends BaseService{ private static $headers = []; private static $cookie = null; public static function get($url, $param =[]) { return self::curl($u