dongpan8928 2015-11-13 02:24
浏览 40

使用CURL在PHP中使用查询字符串和POST数据发送SOAP请求

I am trying to obtain a report from a website which actually has a login mechanism in it. So Far I have been able to do it and preserve the cookie in a file.

        $url = 'https://<site>/action/method/blah';
        $options = array(

            'textUsername' => 'alpha',
            'textPassword'  => 'beta',
            'appId'  => 'gama',
            'browser' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:41.0) Gecko/20100101 Firefox/41.0'
        );
        $cookie_file = APPPATH.'cookies/cookie.txt';
        $postdata = http_build_query($options);

        $ch = curl_init();
        curl_setopt ($ch, CURLOPT_URL, $url);
        curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt ($ch, CURLOPT_USERAGENT, $options['browser']);
        curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
        curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt( $ch, CURLOPT_COOKIESESSION, true );
        curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookie_file );
        curl_setopt( $ch, CURLOPT_COOKIEFILE, $cookie_file );
        curl_setopt ($ch, CURLOPT_REFERER, $url);

        curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
        curl_setopt ($ch, CURLOPT_POST, 1);
        $result = curl_exec ($ch);

        echo $result;
        curl_close($ch);

Now I want to extend this to fetch the report, I intercepted the original request in firefox and It looks contains the following.

Headers, Cookies, Query String, POST Data

In the Headers, It says that the request-type : SOAP Cookie, Query String has key value pairs and POST Data has a XML doc.

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body>......

Can anyone help me to extend my existing code to send the request to fetch the report?

I need answers to the following questions.

Can we use the existing Curl handler $ch to send the second SOAP Request? If Yes, How can we specify it to use the cookie file I created? Also, How can I add the Query String and the XML POST data in the request?

Any help would be much helpful.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看