如何自动验证网络表单?

发布于 2024-10-09 01:31:09 字数 629 浏览 3 评论 0原文

我在 stackoverflow 上找到了这段代码,代码为 https://stackoverflow.com/users/370876/peter-anselmo

$url = 'http://www.targeturl.com';
$myvars = 'myvar1=' . $myvar1 . '&myvar2=' . $myvar2;

$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec( $ch );

我想填写两个字段,一行可以,或者需要两行(使用curl) 我怎样才能像“if”一样测试返回的url是否是我想要的,然后重试(就像循环)。 我知道我问

I found this code on stackoverflow, code of https://stackoverflow.com/users/370876/peter-anselmo

$url = 'http://www.targeturl.com';
$myvars = 'myvar1=' . $myvar1 . '&myvar2=' . $myvar2;

$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec( $ch );

I want to fill two fields, one line is ok or two are needed (with curl)
and how can I make like an "if" to test if the url returned is what I want or no and re-try again (like a loop).
I know I ask

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帅冕 2024-10-16 01:31:09

不太确定你的问题是什么意思,我有点困惑,但你是在问这样的事情吗?

$foundURL = FALSE;
while(!$foundURL)
{
     // Make CURL request
     $response = curl_exec($ch);
     if ($respons == "the url I want") $foundURL = TRUE;
     // Load next http/url for curl request...
}

此循环将继续执行并发出 CURL 请求,直到响应与您正在搜索的某个 URL 匹配...

Not really sure what you mean by your question, I'm sort of confused, but are you asking for something like this?

$foundURL = FALSE;
while(!$foundURL)
{
     // Make CURL request
     $response = curl_exec($ch);
     if ($respons == "the url I want") $foundURL = TRUE;
     // Load next http/url for curl request...
}

This loop will continue to execute and make CURL requests until the response matches some URL that you're searching for ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文