- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在 PHP 脚本中的 CENTOS 7 php5(cli) 和 curl 模块上,我尝试在 PHP 脚本中使用 REST API 制作 POST (JSON),但在我的 CENTOS 7 主机上出现了 PHP 的奇怪行为。
这是脚本的输出:
[+] API GLPI : Session Initializing
User Token ===> YsYJnd81WFiFIJ0pqdW6GqiujUpfkH12tdlgYElj
Init Url ===> http://192.168.158.129:8080/apirest.php/initSession/* About to
connect() to 192.168.158.129 port 8080 (#0)
* Trying 192.168.158.129...
* Connected to 192.168.158.129 (192.168.158.129) port 8080 (#0)
POST /apirest.php/initSession/ HTTP/1.1
Host: 192.168.158.129:8080
Accept: */*
Content-Type: application/json
Authorization: user_token YsYJnd81WFiFIJ0pqdW6GqiujUpfkH12tdlgYElj
Content-Length: -1
Expect: 100-continue
注意:Content-Lenght 设置为 -1
服务器返回我
HTTP/1.1 400 Bad Request
no chunk, no close, no size. Assume close to signal end
Closing connection 0
清漆日志输出
varnish | * << Request >> 32777
varnish | - Begin req 32776 rxreq
varnish | - Timestamp Start: 1522946173.840342 0.000000 0.000000
varnish | - Timestamp Req: 1522946173.840342 0.000000 0.000000
varnish | - HttpGarbage "POST%00"
varnish | - ReqAcct 226 0 226 28 0 28
varnish | - End
varnish |
varnish | * << Session >> 32776
varnish | - Begin sess 0 HTTP/1
varnish | - SessOpen 192.168.158.129 35336 :6081 172.26.0.11 6081 1522946173.840172 20
varnish | - Link req 32777 rxreq
varnish | - SessClose RX_JUNK 0.000
varnish | - End
varnish |
注意:HttpGarbage "POST%00"
uname -a
Linux localhost.localdomain 3.10.0-693.17.1.el7.x86_64 #1 SMP Thu Jan 25
20:13:58 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
rpm -qa | grep -i php
php-common-5.4.16-43.el7_4.1.x86_64
php-process-5.4.16-43.el7_4.1.x86_64
php-xml-5.4.16-43.el7_4.1.x86_64
php-pecl-json-post-1.0.0-2.el7.x86_64
php-cli-5.4.16-43.el7_4.1.x86_64
php-pear-Net-Curl-1.2.5-10.el7.noarch
php-pear-1.9.4-21.el7.noarch
php-mbstring-5.4.16-43.el7_4.1.x86_64
php -v
PHP 5.4.16 (cli) (built: Mar 7 2018 13:34:47)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
rpm -qa | grep -i curl
libcurl-devel-7.29.0-42.el7_4.1.x86_64
libcurl-7.29.0-42.el7_4.1.x86_64
curl-7.29.0-42.el7_4.1.x86_64
python-pycurl-7.19.0-19.el7.x86_64
php-pear-Net-Curl-1.2.5-10.el7.noarch
php -m
[PHP Modules]
bz2
calendar
Core
ctype
curl
date
dom
ereg
exif
fileinfo
filter
ftp
gettext
gmp
hash
iconv
json
json_post
libxml
mbstring
mhash
openssl
pcntl
pcre
Phar
posix
readline
Reflection
session
shmop
SimpleXML
sockets
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlwriter
xsl
zip
zlib
[+] API GLPI : Session Initializing
User Token ===> YsYJnd81WFiFIJ0pqdW6GqiujUpfkH12tdlgYElj
Init Url ===> http://192.168.158.129:8080/apirest.php/initSession/{"session_token":"nmoa5clfg0mfn8g5i153o8iqep"}
Array
( [session_token] => nmoa5clfg0mfn8g5i153o8iqep )
[+] SESSION TOKEN ===> nmoa5clfg0mfn8g5i153o8iqep
[+] API GLPI : TICKET CREATION
{"id":9,"message":"Your ticket has been registered, its treatment is in progress. (Ticket: 9)"}* Hostname was NOT found in DNS cache
* Trying 192.168.158.129...
* Connected to 192.168.158.129 (192.168.158.129) port 8080 (#0)
POST /apirest.php/initSession/ HTTP/1.1
Host: 192.168.158.129:8080
Accept: */*
Content-Type: application/json
Authorization: user_token YsYJnd81WFiFIJ0pqdW6GqiujUpfkH12tdlgYElj
Expect: 100-continue
请注意:没有奇怪的 Content-Lenght 设置为 -1
服务器然后响应
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Date: Thu, 05 Apr 2018 13:08:15 GMT
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
apachehost: 019f184d31ff
Content-Length: 46
Content-Type: application/json; charset=UTF-8
X-Cacheable: NO:Cache-Control=no-store
X-Varnish: 32772
Age: 0
Via: 1.1 varnish (Varnish/5.0)
X-Cache: MISS
Accept-Ranges: bytes
Connection: keep-alive
Connection #0 to host 192.168.158.129 left intact
清漆日志
varnish | * << BeReq >> 16
varnish | - Begin bereq 15 pass
varnish | - Timestamp Start: 1522946334.370154 0.000000 0.000000
varnish | - BereqMethod POST
varnish | - BereqURL /apirest.php/initSession/
varnish | - BereqProtocol HTTP/1.1
varnish | - BereqHeader Host: 192.168.158.129:8080
varnish | - BereqHeader Accept: */*
varnish | - BereqHeader Content-Type: application/json
varnish | - BereqHeader Authorization: user_token YsYJnd81WFiFIJ0pqdW6GqiujUpfkH12tdlgYElj
varnish | - BereqHeader X-Forwarded-For: 192.168.158.1
varnish | - BereqHeader X-Varnish: 16
varnish | - VCL_call BACKEND_FETCH
varnish | - VCL_return fetch
varnish | - BackendOpen 23 boot.NODE019f184d31ff 172.26.0.10 80 172.26.0.11 48398
varnish | - BackendStart 172.26.0.10 80
varnish | - Timestamp Bereq: 1522946334.370492 0.000338 0.000338
varnish | - Timestamp Beresp: 1522946334.480720 0.110566 0.110228
varnish | - BerespProtocol HTTP/1.1
varnish | - BerespStatus 200
varnish | - BerespReason OK
varnish | - BerespHeader Date: Thu, 05 Apr 2018 16:38:54 GMT
varnish | - BerespHeader Server: Apache/2.4.27 (Ubuntu)
(....)
配置
$ php-win.exe -v
PHP 5.5.12 (cli) (built: Apr 30 2014 11:21:04)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans
php-win.exe -m
[PHP Modules]
bcmath
bz2
calendar
com_dotnet
Core
ctype
curl
date
dom
ereg
exif
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
imap
intl
json
ldap
libxml
mbstring
mcrypt
mhash
mysql
mysqli
mysqlnd
odbc
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
tokenizer
wddx
xdebug
xml
xmlreader
xmlrpc
xmlwriter
xsl
zip
zlib
#1st request to get a Session Token
$api_url="http://192.168.158.129:8080/apirest.php";
$usertoken="YsYJnd81WFiFIJ0pqdW6GqiujUpfkH12tdlgYElj";
echo " [+] API GLPI : Session Initializing ";
echo (" User Token ===> " . $usertoken);
$headers = array(
('Content-Type: application/json'),
('Authorization: user_token ' . $usertoken)
);
$initurl=$api_url."/initSession/";
echo ("\n Init Url ===> " . $initurl);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $initurl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$request_result = curl_exec($ch);
echo $request_result;
curl_close($ch);
$obj = json_decode($request_result,true);
print_r ($obj);
$session_token="";
$session_token=$obj['session_token'];
if ($session_token == ""){
echo "FATAL ! Error to retrieve Session Token";
exit(2);
}
echo (" [+] SESSION TOKEN ===> " . $session_token);
....
# Then 2nd request to Post JSON not shown here
最佳答案
向 POST 添加有效负载,因为如果没有帖子内容,curl 将根据您使用的 curl 版本添加 -1 内容长度。更高版本将添加一个 0 长度的内容长度 header ,这可能是您看到不同机器之间存在差异的原因。
$payloadJson = json_encode([]);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payloadJson);
curl_setopt(
$ch,
CURLOPT_HTTPHEADER,
[
"Content-type: application/json",
"Content-Length: ".strlen($payloadJson),
"Authorization: user_token " . $usertoken,
]
);
关于php - CENTOS 7 - curl PHP5 cli 和无效的 Content-Length,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49674447/
我找到了以下代码片段: length = length and length or len(string) 在我看来,这应该等同于: length = length or len(string) 我能
当我使用 numpy.shape() 检查数组的形状时,我有时会得到 (length,1) 有时会得到 (length,)。看起来区别在于列向量与行向量......但它似乎并没有改变数组本身的任何内容
我正在学习 Java,有一个简单的问题。 在设置类的示例中,我看到了这一点: length >= 0 ? length : length * -1 这是什么意思? 谢谢。 最佳答案 这是一种骇人听闻的
我在阅读有关在 Ruby 中重新定义方法有多么容易的文章时遇到了以下问题: class Array alias :old_length :length def length old_l
例如在下面的代码中a和b和c是相等的。 EditText editText; editText = (EditText) findViewById(R.id.edttxt); editText.set
在昨天教授我的 JavaScript 类(class)时,我和我的学生遇到了一些有趣的功能,我认为这些功能可能值得在一个问题和我得出的答案中捕捉到。 在 Chrome 的 JS 控制台中输入 Arra
这个问题在这里已经有了答案: How can I get the size of an array, a Collection, or a String in Java? (3 个回答) 3年前关闭。
这个问题在这里已经有了答案: length and length() in Java (8 个答案) 关闭 6 年前。 我注意到在计算数组的长度时,你会这样写: arrayone.length; 但
console.log(this.slides.length()); 打印 Cannot read property 'length' of undefined.在 setTimeout 为 100
在搜索stackoverflow问题时,我发现了此链接: Error in file.download when downloading custom file。 但是,我的情况有些不同(我认为):
这个问题已经有答案了: Why does R use partial matching? (1 个回答) 已关闭 8 年前。 大家。我刚刚开始使用 swirl 学习 R 编程。 我刚刚了解到seq 。
这个问题已经有答案了: Why does R use partial matching? (1 个回答) 已关闭 8 年前。 大家。我刚刚开始使用 swirl 学习 R 编程。 我刚刚了解到seq 。
这个问题已经有答案了: How can I get the size of an array, a Collection, or a String in Java? (3 个回答) 已关闭 9 年前。
我有一个大数组,其中包含所有类型( bool 值,数组,null,...),并且我正在尝试访问它们的属性arr[i].length,但有些其中显然没有长度。 我不介意那些缺少长度的人是否返回未定义(我
我在对象的属性中有一些文本。我正在测试对象的属性中是否有要显示的文本;如果没有,那么我显示“-”而不是空白。看起来没有什么区别: if (MyObject.SomeText && MyObject.S
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: Why is String.length() a method? Java - Array's length
这个问题在这里已经有了答案: obj.length === +obj.length in javascript (4 个答案) 关闭 9 年前。 我一直在读underscore.js源代码并在 _.
#include using std::cout; using std::cin; using std::string; int main(){ cout > name; cout
我正在细读 underscore.js annotated source当我遇到这个时: if (obj.length === +obj.length) {...} 我现在从this stackove
我正在查看 dotnet 运行时中的一些代码,我注意到不是这样写的: if (args.Length > 0) 他们使用这个: if (args is { Length: > 0}) 你知道用第二种方
我是一名优秀的程序员,十分优秀!