View difference between Paste ID: SDKRWrQC and a4s4yLLu
SHOW: | | - or go back to the newest paste.
1
<?php
2
error_reporting(E_ALL);
3
ini_set('display_errors', '1');
4
5
$showDebugInfo = TRUE;
6
7
$xml = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'.PHP_EOL;
8
$xml .= '<PRICEREQUEST>'.PHP_EOL;
9
$xml .='<LOGIN>'.PHP_EOL;
10
$xml .= '<COMPANY>xxx</COMPANY>'.PHP_EOL;
11
$xml .= '<PASSWORD>xxx</PASSWORD>'.PHP_EOL;
12
$xml .= '<APPID>PC</APPID>'.PHP_EOL;
13
$xml .= '</LOGIN>'.PHP_EOL;
14
$xml .= '<DATASETS>'.PHP_EOL;
15
$xml .='<COUNTRY>1.0</COUNTRY>'.PHP_EOL;
16
$xml .= '<CURRENCY>1.0</CURRENCY>'.PHP_EOL;
17
$xml .= '<POSTCODEMASK>1.0</POSTCODEMASK>'.PHP_EOL;
18
$xml .='<TOWNGROUP>1.0</TOWNGROUP>'.PHP_EOL;
19
$xml .='<SERVICE>1.0</SERVICE>'.PHP_EOL;
20
$xml .='<OPTION>1.0</OPTION>'.PHP_EOL;
21
$xml .='</DATASETS>'.PHP_EOL;
22
$xml .='<PRICECHECK>'.PHP_EOL;
23
$xml .='<RATEID>asasasasasasasas</RATEID>'.PHP_EOL;
24
$xml .='<ORIGINCOUNTRY>GB</ORIGINCOUNTRY>'.PHP_EOL;
25
$xml .='<ORIGINTOWNNAME></ORIGINTOWNNAME>'.PHP_EOL;
26
$xml .='<ORIGINPOSTCODE></ORIGINPOSTCODE>'.PHP_EOL;
27
$xml .='<ORIGINTOWNGROUP></ORIGINTOWNGROUP>'.PHP_EOL;
28
$xml .='<DESTCOUNTRY>AU</DESTCOUNTRY>'.PHP_EOL;
29
$xml .='<DESTTOWNNAME></DESTTOWNNAME>'.PHP_EOL;
30
$xml .='<DESTPOSTCODE></DESTPOSTCODE>'.PHP_EOL;
31
$xml .='<DESTTOWNGROUP></DESTTOWNGROUP>'.PHP_EOL;
32
$xml .='<CONTYPE>D</CONTYPE>'.PHP_EOL;
33
$xml .='<CURRENCY>GBP</CURRENCY>'.PHP_EOL;
34
$xml .='<WEIGHT>0.2</WEIGHT>'.PHP_EOL;
35
$xml .= '<VOLUME>0</VOLUME>'.PHP_EOL;
36
$xml .= '<ITEMS>1</ITEMS>'.PHP_EOL;
37
$xml .='</PRICECHECK>'.PHP_EOL;
38
$xml .='</PRICEREQUEST>';
39
40
41
42
try { 
43
44
    /**
45
     * Content length,
46
     * Use strlen AFTER encoding.
47
    **/
48
    $EncodedHtml = htmlspecialchars( $xml );
49
    $XmlLength = ( strlen( $EncodedHtml ) + 7 );
50
51
    /** 
52
     *  Using the cURL
53
     *  Module within PHP.
54
     *
55
     *  Enable it via HTAccess.
56
    **/
57
    $ch = curl_init("https://express.tnt.com/expressconnect/pricing/getprice"); 
58
    if ( false === $ch )
59
        throw new Exception('failed to initialize');
60
61
    /** 
62
     *  cURL Options
63
     *      -  Use Program's Custom Headers
64
     *      -  Use \n to separate headers
65
    **/
66
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
67
    curl_setopt($ch, CURLOPT_PORT, 81 );
68
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1 );
69
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1 );
70
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
71
        // curl_setopt($ch, CURLOPT_HTTPHEADER, array(
72
            // "POST PriceGate.asp HTTP/1.0\n",
73
            // "Accept: */*\n",
74
            // "User-Agent: PriceGate_socket/1.0\n",
75
            // "Content-type: application/x-www-form-urlencoded;\n",
76
            // "Content-length: ". ( $XmlLength ) ."\n",
77
            // "\n",
78
            // "xml_in=". $EncodedHtml.""
79
        // ));
80
    
81
    
82
83
    if ( $showDebugInfo ) {
84
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true );
85
        curl_setopt($ch, CURLOPT_FAILONERROR, true);    
86
    }
87
88
    $output = curl_exec($ch);
89
90
    if ( false === $output )
91
        throw new Exception( curl_error( $ch ), curl_errno( $ch ));
92
    else
93
        echo $output;
94
95
    curl_close($ch);
96
97
 } catch( Exception $e ) {
98
99
 /**
100
  * Display All Errors!
101
 **/
102
 trigger_error(sprintf(
103
        'Curl failed with error #%d: %s',
104
        $e->getCode(), $e->getMessage()), E_USER_ERROR);
105
 }
106
107
   
108
109
110
   
111
?>