php curl发送表单格式数据格式_PHP 里 curl POST 提交文件到底应该怎么写呀

9

2019-11-14 16:04:37 +08:00

google: sm.ms 403

https://www.v2ex.com/t/369007

```bash

liuxu:/tmp$ cat post.php

$ch = curl_init();

$fd = curl_file_create('/home/liuxu/Downloads/1.png', 'image/png', '1.png');

$file = array('smfile' => $fd);

curl_setopt($ch, CURLOPT_URL, "https://sm.ms/api/v2/upload");

curl_setopt($ch, CURLOPT_VERBOSE, 1);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data', 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36'));

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_POSTFIELDS, $file);

$rs = curl_exec($ch);

curl_close($ch);

var_dump($rs);

?>

liuxu:/tmp$ php post.php

* Trying 47.88.229.110...

* TCP_NODELAY set

* Connected to sm.ms (47.88.229.110) port 443 (#0)

* ALPN, offering http/1.1

* successfully set certificate verify locations:

* CAfile: /etc/ssl/certs/ca-certificates.crt

CApath: /etc/ssl/certs

* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384

* ALPN, server accepted to use http/1.1

* Server certificate:

* subject: OU=Domain Control Validated; OU=ShinoSaki MDV; CN=sm.ms

* start date: Jan 2 00:00:00 2017 GMT

* expire date: Jan 2 23:59:59 2020 GMT

* subjectAltName: host "sm.ms" matched cert's "sm.ms"

* issuer: C=GB; ST=Greater Manchester; L=Salford; O=COMODO CA Limited; CN=COMODO RSA Domain Validation Secure Server CA

* SSL certificate verify ok.

> POST /api/v2/upload HTTP/1.1

Host: sm.ms

Accept: */*

User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36

Content-Length: 59028

Content-Type: multipart/form-data; boundary=------------------------0dc5337c392dd914

Expect: 100-continue

< HTTP/1.1 100 Continue

< HTTP/1.1 200 OK

< Server: nginx

< Date: Thu, 14 Nov 2019 08:02:36 GMT

< Content-Type: text/html; charset=UTF-8

< Transfer-Encoding: chunked

< Connection: keep-alive

< Vary: Accept-Encoding

< Set-Cookie: PHPSESSID=1qsrkiqn676norodn0qnl3peln; path=/

< Expires: Thu, 19 Nov 1981 08:52:00 GMT

< Cache-Control: no-store, no-cache, must-revalidate

< Pragma: no-cache

< Strict-Transport-Security: max-age=63072000; includeSubDomains; preload

< X-Frame-Options: SAMEORIGIN

< X-Content-Type-Options: nosniff

< X-XSS-Protection: 1; mode=block

< X-Custom-Job: If you see this, please contact [email protected] for a job

< Access-Control-Allow-Origin: *

< Access-Control-Allow-Methods: OPTIONS, HEAD, GET, POST

< Allow: GET, POST, HEAD

< Set-Cookie: cid=rBWawl3NChysdVkoQsGLAg==; expires=Thu, 31-Dec-37 23:55:55 GMT; domain=sm.ms; path=/

<

* Connection #0 to host sm.ms left intact

string(481) "{"success":true,"code":"success","message":"Upload success.","data":{"file_id":0,"width":715,"height":645,"filename":"1.png","storename":"rng9GNzEhBCMUQA.png","size":58844,"path":"\/2019\/11\/14\/rng9GNzEhBCMUQA.png","hash":"QChs79nUXbdZW6ygYDVOBvjGNe","url":"https:\/\/i.loli.net\/2019\/11\/14\/rng9GNzEhBCMUQA.png","delete":"https:\/\/sm.ms\/delete\/QChs79nUXbdZW6ygYDVOBvjGNe","page":"https:\/\/sm.ms\/image\/rng9GNzEhBCMUQA"},"RequestId":"3985A52B-A6C8-4F22-A96A-749E3C77D35E"}"

```

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值