cari

PHP模拟POST的方法

PHP主动POST数据到JSP

采用哪种方式好?

最好有例子,谢谢

------解决方案--------------------
后台模拟 哪种都差不多 最常用的curl模块
------解决方案--------------------

PHP code

function post_url($url, $post = "", $host = "www.ydtuiguang.com", $referrer = 'http://www.ydtuiguang.com/', $proxy = -1){
    if(function_exists("curl_init")){
        $ch = @curl_init();
        @curl_setopt($ch, CURLOPT_URL, $url);
        if(!empty($proxy["address"]))
            @curl_setopt($ch, CURLOPT_PROXY, strpos($proxy["address"], "http") === 0 ? $proxy["address"] : "http://".$proxy["address"]);
        if(!empty($proxy["account"]) && !empty($proxy["password"]))
            @curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy["account"].":".$proxy["password"]);
        @curl_setopt($ch, CURLOPT_REFERER, $referrer);
        @curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.0)");
        @curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIE_FILE_PATH);
        @curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIE_FILE_PATH);
        @curl_setopt($ch, CURLOPT_HEADER, 0);
        @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        @curl_setopt($ch, CURLOPT_TIMEOUT, 1000);

        if (!empty($post)) {
            @curl_setopt($ch, CURLOPT_POST, 1);
            @curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
        }

        $result = @curl_exec($ch);
        @curl_close($ch);
    }elseif(function_exists("fsockopen")){
        $httpheader = "POST ".$url." HTTP/1.1\r\n";   
        $httpheader .= "Accept: */*\r\n";   
        $httpheader .= "Accept-Language: zh-cn\r\n";   
        $httpheader .= "Referer: ".$referrer."\r\n";   
        $httpheader .= "Content-Type: application/x-www-form-urlencoded\r\n";   
        $httpheader .= "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)\r\n";   
        $httpheader .= "Host: ".$host."\r\n";   
        $httpheader .= "Content-Length: ".strlen($post)."\r\n";   
        $httpheader .= "Connection: Keep-Alive\r\n";   
        $httpheader .= "\r\n";   
        $httpheader .= $post;   
        $fd = fsockopen($host, 80);   
        fwrite($fd, $httpheader);   
        $result = "";   
        while(!feof($fd)){   
            $result .= fread($fd, 8192);   
        }   
        fclose($fd);   
    }elseif(function_existes('file_get_contents')){
        $httpheader = "POST ".$url." HTTP/1.1\r\n";   
        $httpheader .= "Accept: */*\r\n";   
        $httpheader .= "Accept-Language: zh-cn\r\n";   
        $httpheader .= "Referer: ".$referrer."\r\n";   
        $httpheader .= "Content-Type: application/x-www-form-urlencoded\r\n";   
        $httpheader .= "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)\r\n";   
        $httpheader .= "Host: ".$host."\r\n";   
        $httpheader .= "Content-Length: ".strlen($post)."\r\n";   
        $httpheader .= "Connection: Keep-Alive\r\n";   
        
        $opts = array(
           'http'=>array(
                'method'=>"POST",
                'header'=>$httpheader,
                'content'=>$post
           )
         );            
        $context = stream_context_create($opts);
        $result = file_get_contents($url, 'r', $context);
    }
    return $result;
}
<br><font color="#e78608">------解决方案--------------------</font><br>
探讨

后台模拟 哪种都差不多 最常用的curl模块
Kenyataan
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Kontena Suntikan Ketergantungan PHP: Permulaan yang cepatKontena Suntikan Ketergantungan PHP: Permulaan yang cepatMay 13, 2025 am 12:11 AM

AphpdependencyInjectionContainerisatoLthatMatagesClassDependencies, EnhancingCodeModularity, Testability, andMaintainability.itactsascentralHubforcreatingandinjectingdependencies, sheReducingTightCouplingandeaseaseaseSunittesting.

Suntikan ketergantungan berbanding pencari perkhidmatan di phpSuntikan ketergantungan berbanding pencari perkhidmatan di phpMay 13, 2025 am 12:10 AM

Pilih DependencyInjection (DI) Untuk aplikasi besar, servicelocator sesuai untuk projek kecil atau prototaip. 1) DI meningkatkan kesesuaian dan modulariti kod melalui suntikan pembina. 2) ServiceLocator memperoleh perkhidmatan melalui pendaftaran pusat, yang mudah tetapi boleh menyebabkan peningkatan gandingan kod.

Strategi Pengoptimuman Prestasi PHP.Strategi Pengoptimuman Prestasi PHP.May 13, 2025 am 12:06 AM

Phpapplicationscanbeoptimizedforspeedandeficiencyby: 1) enablingopcacheinphp.ini, 2) menggunakan preparedSwithpdofordatabasequeries, 3) menggantikanloopswitharray_filterandarray_mapfordataprocessing, 4) configuringnginywinginywinyvinyvinginy

Pengesahan E -mel PHP: Memastikan e -mel dihantar dengan betulPengesahan E -mel PHP: Memastikan e -mel dihantar dengan betulMay 13, 2025 am 12:06 AM

PhpeMailvalidationInvolvestHreesteps: 1) formatValidationingRegularExpressionStocheckTheemailFormat; 2) dnsvalidationtoensurethedomainhasavalidmxrecord;

Cara membuat aplikasi php lebih cepatCara membuat aplikasi php lebih cepatMay 12, 2025 am 12:12 AM

Tomakephpapplicationsfaster, ikutiTheseSteps: 1) UseopcodecachinglikeopcachetostorePrecompiledscriptbytecode.2) minimizedatabasequeriesbyusingquerycachingandeficientindexing.3)

Senarai Semak Pengoptimuman Prestasi PHP: Meningkatkan Kelajuan SekarangSenarai Semak Pengoptimuman Prestasi PHP: Meningkatkan Kelajuan SekarangMay 12, 2025 am 12:07 AM

ToimprovePhpapPlicationspeed, ikutiTheSesteps: 1) EnableopCodeCachingWithApcutoreduceScriptExecutionTime.2) pelaksanaanDatabasequerycachingingPdotominimizedataBaseHits.3)

Suntikan Ketergantungan PHP: Meningkatkan kebolehlaksanaan kodSuntikan Ketergantungan PHP: Meningkatkan kebolehlaksanaan kodMay 12, 2025 am 12:03 AM

Suntikan ketergantungan (DI) dengan ketara meningkatkan kesesuaian kod PHP oleh kebergantungan transitif secara eksplisit. 1) Kelas Decoupling dan pelaksanaan khusus menjadikan ujian dan penyelenggaraan lebih fleksibel. 2) Di antara tiga jenis, pembina menyuntik kebergantungan ekspresi eksplisit untuk memastikan keadaan konsisten. 3) Gunakan bekas DI untuk menguruskan kebergantungan kompleks untuk meningkatkan kualiti kod dan kecekapan pembangunan.

Pengoptimuman Prestasi PHP: Pengoptimuman Pertanyaan Pangkalan DataPengoptimuman Prestasi PHP: Pengoptimuman Pertanyaan Pangkalan DataMay 12, 2025 am 12:02 AM

DatabaseQueryoptimizationInpinvolvesseverSlegatiesToenhancePratePratePratePratePratePregiesToRperformance.1) selectOnlynessaryColumnStoReducedatatatransfer.2) UseIndexingTospeedupdatareTrieval.3) PrevancequerycachingToStoreresultSoffReFfeFfffffffffffffffffffffffffffffffffffffffffffferseprewfffffffffffersepresseprespersepresperseprespersepresperseprespersepresperseprespers

See all articles

Alat AI Hot

Undresser.AI Undress

Undresser.AI Undress

Apl berkuasa AI untuk mencipta foto bogel yang realistik

AI Clothes Remover

AI Clothes Remover

Alat AI dalam talian untuk mengeluarkan pakaian daripada foto.

Undress AI Tool

Undress AI Tool

Gambar buka pakaian secara percuma

Clothoff.io

Clothoff.io

Penyingkiran pakaian AI

Video Face Swap

Video Face Swap

Tukar muka dalam mana-mana video dengan mudah menggunakan alat tukar muka AI percuma kami!

Artikel Panas

Mandragora: Whispers of the Witch Tree - Cara Membuka Kunci Cangkuk Bergelut
3 minggu yang laluBy尊渡假赌尊渡假赌尊渡假赌
Nordhold: Sistem Fusion, dijelaskan
3 minggu yang laluBy尊渡假赌尊渡假赌尊渡假赌

Alat panas

MinGW - GNU Minimalis untuk Windows

MinGW - GNU Minimalis untuk Windows

Projek ini dalam proses untuk dipindahkan ke osdn.net/projects/mingw, anda boleh terus mengikuti kami di sana. MinGW: Port Windows asli bagi GNU Compiler Collection (GCC), perpustakaan import yang boleh diedarkan secara bebas dan fail pengepala untuk membina aplikasi Windows asli termasuk sambungan kepada masa jalan MSVC untuk menyokong fungsi C99. Semua perisian MinGW boleh dijalankan pada platform Windows 64-bit.

Dreamweaver Mac版

Dreamweaver Mac版

Alat pembangunan web visual

MantisBT

MantisBT

Mantis ialah alat pengesan kecacatan berasaskan web yang mudah digunakan yang direka untuk membantu dalam pengesanan kecacatan produk. Ia memerlukan PHP, MySQL dan pelayan web. Lihat perkhidmatan demo dan pengehosan kami.

Versi Mac WebStorm

Versi Mac WebStorm

Alat pembangunan JavaScript yang berguna

Hantar Studio 13.0.1

Hantar Studio 13.0.1

Persekitaran pembangunan bersepadu PHP yang berkuasa