我正在尝试登录到远程网站,这要求我发布用户名密码并通过帖子登录。我正在使用Curl选项
curl_setopt($ch, CURLOPT_POSTFIELDS , $postData);
并这样分配我的信息
$postData['email'] = 'smart@acme.com';
$postData['password'] = 'Secret';
$postData['Submit']='Login';
但是远程服务器抱怨
HTTP Error 411. The request must be chunked or have a content length.
那我怎么知道我的postData的内容长度?
答案 0 :(得分:0)
要获取PostData的长度,可以使用PHP的函数my_connect
来获取。
尝试:
count
上面的代码具有计算postData数组的长度,然后设置Curl标头的功能,如果您要查找1行代码,请尝试以下操作:
#Get the length
$postData_len = count($postData);
#Set Curl Header with Content Length
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Length: '.$postData_len));
答案 1 :(得分:0)
不确定是否适合您吗?,但是您需要使用import csv
new_dict = {}
with open("your_csv_file.csv","r",newline="") as f:
result = csv.reader(f)
next(result, None)
for row in result:
transaction = int(row[0])
client = int(row[1])
amount = float(row[2])
if client in new_dict:
new_dict[client][transaction] = amount
else:
new_dict[client] = {transaction:amount}
print (new_dict)
这样的东西来设置 Content-Length 。
{'1': {'1': '10.5', '2': '3', '3': '2.75'}, '2': {'4': '90'}, '3': {'5': '25', '6': '0.05'}}
答案 2 :(得分:0)
$ch = curl_init();
$data['email'] = 'smart@acme.com';
$data['password'] = 'Secret';
$data['Submit']='Login';
curl_setopt($ch, CURLOPT_URL, '****/upload.php');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);
请求的标头是
[CONTENT_LENGTH] => 357
[CONTENT_TYPE] =>多部分/表单数据;边界= ------------------------ aac448045c2fe517
但是如果我们将args传递给这样的字符串
$ch = curl_init();
$data['email'] = 'smart@acme.com';
$data['password'] = 'Secret';
$data['Submit']='Login';
echo strlen(http_build_query($data));
curl_setopt($ch, CURLOPT_URL, '*/upload.php');
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_exec($ch);
,此请求的标头是
[CONTENT_LENGTH] => 51
[CONTENT_TYPE] => application / x-www-form-urlencoded
因此,application/x-www-form-urlencoded
比multipart/form-data
更好,因为它易于计算内容长度