php-curl

举报
风吹稻花香 发表于 2021/06/04 23:18:14 2021/06/04
【摘要】 use anlutro\cURL\cURL; $curl = new cURL; $post_data= array ("sname" => "dlrmcf58", "spwd" => "ZRB2aP8K", "scorpid" => "1", "sprdid" => 11,"sdst" => 18601924901, "smsg...

use anlutro\cURL\cURL;

$curl = new cURL;

$post_data= array ("sname" => "dlrmcf58",

"spwd" => "ZRB2aP8K",

"scorpid" => "1",

"sprdid" => 11,"sdst" => 18601924901,

"smsg" => rawurlencode("zhuce")

);

//$response = $curl->post("http://cf.lmobile.cn/submitdata/Service.asmx/g_Submit","sname=dlrmcf58&spwd=ZRB2aP8K&scorpid=&sprdid=100&sdst=18601924901&smsg=".rawurlencode("zhuce"));

$response = $curl->post("http://cf.lmobile.cn/submitdata/Service.asmx/g_Submit",$post_data);

 echo $response ;


https://github.com/anlutro/php-curl

 

 composer require anlutro/curl

 

Optionally, add 'cURL' => 'anlutro\cURL\Laravel\cURL' to the array of aliases in config/app.php.

 

Usage

 

$curl = new anlutro\cURL\cURL;

 

$response = $curl->get('http://www.google.com');

 

// easily build an url with a query string

$url = $curl->buildUrl('http://www.google.com', ['s' => 'curl']);

$response = $curl->get($url);

 

// the post, put and patch methods takes an array of POST data

$response = $curl->post($url, ['api_key' => 'my_key', 'post' => 'data']);

 

// add "json" to the start of the method to convert the data to a JSON string

// and send the header "Content-Type: application/json"

$response = $curl->jsonPost($url, ['post' => 'data']);

 

// if you don't want any conversion to be done to the provided data, for example

// if you want to post an XML string, add "raw" to the start of the method

$response = $curl->rawPost($url, '<?xml version...');

 

// raw request are also the easiest way to upload files

$file = curl_file_create('/path/to/file');

$response = $curl->rawPost($url, ['file' => $file]);

 

// a response object is returned

var_dump($response->statusCode); // response status code integer (for example, 200)

var_dump($response->statusText); // full response status (for example, '200 OK')

echo $response->body;

var_dump($response->headers); // array of headers

var_dump($response->info); // array of curl info

 

If you need to send headers or set cURL options you can manipulate a request object directly. send() finalizes the request and returns the result.

 

// newRequest, newJsonRequest and newRawRequest returns a Request object

$request = $curl->newRequest('post', $url, ['foo' => 'bar'])

    ->setHeader('Accept-Charset', 'utf-8')

    ->setHeader('Accept-Language', 'en-US')

    ->setOption(CURLOPT_CAINFO, '/path/to/cert')

    ->setOption(CURLOPT_FOLLOWLOCATION, true);

$response = $request->send();

 

You can also use setHeaders(array $headers) and setOptions(array $options) to replace all the existing options.

 

Note that some curl options are reset when you call send(). Look at the source code of the method cURL::prepareMethod for a full overview of which options are overwritten.

 

HTTP basic authentication:

 

$request = $curl->newRequest('post', $url, ['foo' => 'bar'])

    ->setUser($username)->setPass($password);

 

Laravel

 

The package comes with a facade you can use if you prefer the static method calls over dependency injection.

 

You do not need to add a service provider.

 

Optionally, add 'cURL' => 'anlutro\cURL\Laravel\cURL' to the array of aliases in config/app.php.

 

Replace $curl-> with cURL:: in the examples above.

 

 

文章来源: blog.csdn.net,作者:网奇,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/jacke121/article/details/55549169

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。