使用php curl自动填充文本区域 [英] To auto fill a text area using php curl

查看:107
本文介绍了使用php curl自动填充文本区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试自动填充具有文本区域的表单.

We are trying to auto populate a form which is having a text area.

<textarea name="myarea"></textarea>

我们可以使用curl来完成它,但是它只接受输入文本的一部分.如果内容太大,则不接受任何内容.文本区域上的字符数没有限制.

We can do it using curl however it is accepting only the part of the input text. If the content is too large then it accepts nothing. There is no restriction with respect to number of characters on the text area.

$area['myarea']=>"a large html code.................."
curl_setopt($ch,CURL_POSTFIELDS,$area);
curl_execute();

请提出解决方案.

推荐答案

确定要正确地对参数进行转义吗?只需为此使用urlencode().这是一个示例:

Are you sure you escaped the parameter correctly? Just use urlencode() for this purpose. Here is an example:

<?php
$url = 'http://localhost/';

$fields = array (
  'param1' => 'val1',
  'param2' => 'val2'
);

$qry = '';
foreach ($fields as $key => $value) {
  $qry .= $key . '=' . urlencode($value) . '&';
}
$qry = rtrim($qry, '&');

// Alternatively, you can also use $qry = http_build_query($fields, '');

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $qry);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);

curl_close($ch);

var_dump($result);
?>

如果要验证请求是否已正确发送,我建议使用netcat.只需将URL设置为 http://localhost:3333/,然后使用以下命令执行netcat: $ nc -l -p 3333

If you want to verify that the request was send properly, I would recommend netcat. Just set the URL to http://localhost:3333/ and then execute netcat using: $ nc -l -p 3333

与预期的一样,该请求如下所示: POST/HTTP/1.1 主机:localhost:3333 接受:/ 内容长度:23 内容类型:application/x-www-form-urlencoded

As expected, the request looks like this: POST / HTTP/1.1 Host: localhost:3333 Accept: / Content-Length: 23 Content-Type: application/x-www-form-urlencoded

param1=val1&param2=val2

这篇关于使用php curl自动填充文本区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆