-1

Since Wikimapia has a problem with updating the key limit, I want to autogenerate them through cURL and then save them to the database. How can I implement this? I am authorized on the site like this

// URL скрипта авторизации
$login_url = 'http://wikimapia.org/user/login/';

// параметры для отправки запроса - логин и пароль
$post_data = 'username=LOGIN&pw1=PASSWORD&_time=3306';

// создание объекта curl
$ch = curl_init();

// используем User Agent браузера
$agent = $_SERVER["HTTP_USER_AGENT"];
curl_setopt($ch, CURLOPT_USERAGENT, $agent);

// задаем URL
curl_setopt($ch, CURLOPT_URL, $login_url );

// указываем что это POST запрос
curl_setopt($ch, CURLOPT_POST, 1 );

// задаем параметры запроса
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

// указываем, чтобы нам вернулось содержимое после запроса
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// в случае необходимости, следовать по перенаправлени¤м
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

/*
    Задаем параметры сохранени¤ cookie
    как правило Cookie необходимы для дальнейшей работы с авторизацией
*/

curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');

When I post Wikimapia request:

http://wikimapia.org/api/?action=create_key_process&readed_eula=true&api_use=1&site_name=&application_name=333&platform=333

I get an error You should read and agree EULA`s. How do I pass the checkbox flag correctly?

<label for="readed_eula" class="checkbox">
            <input type="checkbox" id="readed_eula" name="readed_eula" value="true"> I have read Wikimapia Terms of Service
        </label>
Urban Side
  • 81
  • 8
  • I don't know anything about Wikimapia, and you haven't told us what their API expects, but the code you show is only POSTing the `username`, `pw1` and `_time` fields. Is `readed_eula`, and all other fields you have in the GET query string, meant to be POSTed as well? – Don't Panic Oct 17 '19 at 08:38

2 Answers2

0

Try to change this

$post_data = 'username=LOGIN&pw1=PASSWORD&_time=3306';

into this:

$post_data = http_build_query([
  'username' => 'LOGIN',
  'pw1' => 'PASSWORD',
  '_time' => '3306',
  'readed_eula' => 'true',
]);
Koala Yeung
  • 7,475
  • 3
  • 30
  • 50
  • 1
    Everything works in the authorization request) I need a new request to create a key I post **true** but I get an error that I did not check the box. – Urban Side Oct 17 '19 at 08:42
0

Made my post by answer Koala Yeung , and all work))THX

  // выполняем запрос для авторизации
    $postResult = curl_exec($ch);
    $timeout = 5; // set to zero for no timeout
    $url2= "http://wikimapia.org/api/?action=create_key_process";
    $post_data = http_build_query([
      'readed_eula' => 'true',
      'api_use' => 1,
      'site_name' => '',
      'application_name' => '444',
      'platform' => '444',
    ]);
    // задаем URL
    curl_setopt($ch, CURLOPT_URL, $url2 );

    // указываем что это POST запрос
    curl_setopt($ch, CURLOPT_POST, 1 );

    // задаем параметры запроса
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

    // указываем, чтобы нам вернулось содержимое после запроса
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    // в случае необходимости, следовать по перенаправлени¤м
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    $test = curl_exec($ch);
Urban Side
  • 81
  • 8