Привет.
Этот пост не несет в себе ничего нового, просто делюсь простым скриптом.
Скрипт предназначен для генерации кода из аргументов в строке запуска cURL. Для чего это нужно? Для ускорения написания некоторых программ, которые активно работают с интернетом.
В последних версиях хрома в инспекторе появилась кнопка, которая позволяет копировать запрос как cURL строка. Выглядит этот пункт так:
После копирования, в буфере появляется примерно такая строка:
curl "http://vk.com/al_im.php" -H "Cookie: remixlang=0; remixdt=0; remixrefkey=3dd1be1f57376b7f5f; remixseenads=1; remixsid=7fc4732d4af03745a7891833cfbae2add824a74eef6d40bd62fe0; audio_vol=58; remixflash=11.7.700; arp_scroll_position=5562" -H "Origin: http://vk.com" -H "Accept-Encoding: gzip,deflate,sdch" -H "Host: vk.com" -H "Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4" -H "User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31" -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: */*" -H "Referer: http://vk.com/im?peers=175277028&sel=175277028" -H "X-Requested-With: XMLHttpRequest" -H "Connection: keep-alive" -H "Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.3" --data "act=a_send&al=1&hash=d82cdecf7730caf855&media=&msg=%41D%430%43F%438%448%438%20%43F%43E%43B%443%447%430%442%435%43B%44E%20%441%43B%43E%432%43E%20%431%430%444%43E%435%434%2E%43D%435%442%20%438%20%43F%43E%43B%443%447%438%20%43F%43E%434%430%440%43A%443%20%3A%33&title=&to=175277028&ts=1670227198"
Эту строчку надо скопировать в скрипт и он сгенерирует следующий код:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | <?php function curl($url, $headers, $post) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); $response = curl_exec($ch); curl_close($ch); return $response; } $headers = array ( 'Cookie' => 'remixlang=0; remixdt=0; remixrefkey=3dd1be1f57376b7f5f; remixseenads=1; remixsid=7fc4732d4af03745a7891833cfbae2add824a74eef6d40bd62fe0; audio_vol=58; remixflash=11.7.700; arp_scroll_position=5562', 'Origin' => 'http://vk.com', 'Accept-Encoding' => 'gzip,deflate,sdch', 'Host' => 'vk.com', 'Accept-Language' => 'ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4', 'User-Agent' => 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31', 'Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => '*/*', 'Referer' => 'http://vk.com/im?peers=175277028&sel=175277028', 'X-Requested-With' => 'XMLHttpRequest', 'Connection' => 'keep-alive', 'Accept-Charset' => 'windows-1251,utf-8;q=0.7,*;q=0.3', ); $post = array ( 'act' => 'a_send', 'al' => '1', 'hash' => 'd82cdecf7730caf855', 'media' => '', 'msg' => '%41D%430%43F%438%448%438%20%43F%43E%43B%443%447%430%442%435%43B%44E%20%441%43B%43E%432%43E%20%431%430%444%43E%435%434%2E%43D%435%442%20%438%20%43F%43E%43B%443%447%438%20%43F%43E%434%430%440%43A%443%20%3A%33', 'title' => '', 'to' => '175277028', 'ts' => '1670227198', ); curl('http://vk.com/al_im.php', $headers, $post); ?> |
Или такой
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | String urlParameters = "act=a_send&al=1&hash=d82cdecf7730caf855&media=&msg=%41D%430%43F%438%448%438%20%43F%43E%43B%443%447%430%442%435%43B%44E%20%441%43B%43E%432%43E%20%431%430%444%43E%435%434%2E%43D%435%442%20%438%20%43F%43E%43B%443%447%438%20%43F%43E%434%430%440%43A%443%20%3A%33&title=&to=175277028&ts=1670227198&"; String request = "http://vk.com/al_im.php"; URL url = new URL(request); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setDoInput(true); connection.setInstanceFollowRedirects(false); connection.setRequestMethod("POST"); connection.setRequestProperty("Cookie", "remixlang=0; remixdt=0; remixrefkey=3dd1be1f57376b7f5f; remixseenads=1; remixsid=7fc4732d4af03745a7891833cfbae2add824a74eef6d40bd62fe0; audio_vol=58; remixflash=11.7.700; arp_scroll_position=5562"); connection.setRequestProperty("Origin", "http://vk.com"); connection.setRequestProperty("Accept-Encoding", "gzip,deflate,sdch"); connection.setRequestProperty("Host", "vk.com"); connection.setRequestProperty("Accept-Language", "ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4"); connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31"); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestProperty("Accept", "*/*"); connection.setRequestProperty("Referer", "http://vk.com/im?peers=175277028&sel=175277028"); connection.setRequestProperty("X-Requested-With", "XMLHttpRequest"); connection.setRequestProperty("Connection", "keep-alive"); connection.setRequestProperty("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.3"); connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length)); connection.setUseCaches (false); DataOutputStream wr = new DataOutputStream(connection.getOutputStream ()); wr.writeBytes(urlParameters); wr.flush(); wr.close(); connection.disconnect(); |
В скрипте реализована Java и PHP, языки добавляются просто, думаю по коду сами разберетесь.
Проверить работу, посмотреть и забрать сорцы можно тут: https://blog.bafoed.ru/curlparser.html
P.S. Претензии по качеству кода принимаются, старался писать без костылей.