' Step 1: Build the string request that will be sent to Sell Online
' The string is XML formatted and will contain
' information such as destination address and
' the list of items the consumer ordered
'
' TO DO : BUILD YOUR XML STRING HERE
' Important Note:
' --------------
' This sample is using merchant ID: "CPC_DEMO_HTML"
' Instead, you should use the merchant ID assigned to you by
' Canada Post -and- make sure that your profile is configured
' to return HTML (otherwise, you will receive XML and need an XML parser
' to understand it).
Dim xmlRequest
xmlRequest = "
en
CPC_DEMO_HTML
-
1
1.5
1
1
1
My Sample Item
Wisconsin
CANADA
H3K1E5
"
Step 2: The request has to be sent to Sell Online via an HTTP(S) POST request.
Below is the sample request in Java for sending through HTTP(S) POST
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
public class SendXmlRequest {
public static void main(String[] args) throws ClientProtocolException, IOException {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("https://sellonline.canadapost.ca/sellonline/Rating");
StringEntity input = new StringEntity("XMLRequest");
post.setEntity(input);
HttpResponse response = client.execute(post);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
}
}
Step 3 : Incorporate the response in your application page. Below is the sample response from sell online :
1
OK
1
1.0
0
Expedited
21.99
2018-09-10
2018-09-11
3
false
P_0
Regular
22.12
2018-09-10
2018-09-13
5
false
P_0
P_0
My Sample Item
2.0
1.5
30.0
20.0
20.0
1
My Sample Item
No
Yes
No