duanbai5348 2014-06-30 03:44
浏览 68
已采纳

PHP curl表单没有动作和js事件

I'm trying to use curl to post some data and retrieve it from a website that isn't mine, the websites form doesn't seem to have a form action and the page doesn't reload when you submit the data and there also seems to be some js behind the click of the button.

$url = "http://emonitoring.poczta-polska.pl/#";

$parm = "numer=RR123456789PL";

and here is the curl:

array(
  CURLOPT_URL   =>  $url,     
  CURLOPT_POST  =>  TRUE,
  CURLOPT_POSTFIELDS     => $parm,
  CURLOPT_RETURNTRANSFER => TRUE,
  CURLOPT_FOLLOWLOCATION => TRUE
);

I execute and init the curl as expected, just showing the important parts. Here is also the live http headers output:

    POST /wssClient.php HTTP/1.1
Host: emonitoring.poczta-polska.pl
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Content-Type: application/x-www-form-urlencoded
Origin: http://kody.poczta-polska.pl
Referer: http://kody.poczta-polska.pl/
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36

HTTP/1.1 200 OK
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Content-Length: 1215
Content-Type: text/html; charset=UTF-8
Date: Mon, 30 Jun 2014 03:31:59 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Pragma: no-cache
Server: Apache
X-Cnection: close

At the moment it just shows the page and it doesn't look like that form was submitted, I've also tried putting the url as: "http://emonitoring.poczta-polska.pl/wssClient.php" and just get told to enter the number.

  • 写回答

2条回答 默认 最新

  • dtnpf35197 2014-06-30 04:02
    关注

    In such cases you go to chrome, hit F12, go to network, submit the form and see what is sent to the server. I see this posted

    s:fggsbnqu033gqiipemr50fer56
    n:RR123456789PL
    l:
    

    If you view source you see

    if (jQuery('#numer').val().length == 19) {
      var numer = dodajck(jQuery('#numer').val())
    } else var numer = jQuery('#numer').val();
    
    
    jQuery.ajax({
      type: 'post',
      cache: true,
      dataType: 'html',
      data: ({
        s: 'fggsbnqu033gqiipemr50fer56',
        n: numer,
        l: ''
    }),
    url: 'wssClient.php',
    

    The s:.... could mean you need to have a session on their server to be able to call the wssClient - if so, you will need to CURL with sessions

    If you can call their server without a session or you have a session before you call you can curl using the parm is n= and not numer= and you need to have calculated the checksum using their function which can easily be translated to PHP

    function dodajck(numer) {
        // dodatkowe sprawdzenia i określenie wag oraz części numeru, która
        // ma zostać zważona
        //String wagi;
        //String doWazenia;
    
        var wagi = "3131313131313131313";
        var doWazenia = String(numer);
        // wyliczenie sumy iloczynów waga * cyfra
        var suma = 0;
        for (var i = 0; i < 19; i++)
        suma = suma + Number(doWazenia.substring(i, i + 1)) * Number(wagi.substring(i, i + 1));
        // ostateczne sprawdzenia
    
    
        // przykład numeru 20-cyfrowego
        // 00
        // 1 - rodzaj?
        // 590 -- kraj 590 = PL
        // 0773 -- firma 0773 = PP
        // 3 -- rodzaj przesyłki
        // 12345678 - numer przesyłki
        // 9 - CK
        // ważone są numery od 1 do 19
        var ck = 10 - suma % 10;
        if (ck == 10) ck = 0;
    
        return String(numer) + String(ck);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复