tousif tousif - 5 months ago 48
PHP Question

Using PFC shipping API in PHP

I am trying to use pfc shippiong api
http://www.pfcexpress.com/webservice/EnAPIDoc.html

I am trying to run the simple getCountry method, the first one on that page.
You can also find it working on this page
http://bit.ly/1Lq4t6G
Just use the key pfc123456789 and hit search

My problem is that their example on the tutorial in the first link is for .Net and I know php only and integrating this in php

According to their tutorial

FOR .NET
First step:In your own project:asp.net,add web quotation,Provide the API service website address offered by PFC. Be assumed to be:"http://pfcexpress.com/webservice/APIWebService.asmx"

Second step:Initialization,then use the method,can obtain the data
pfc.pfcwebservice p=new pfc.pfcwebservice();
string result = p.getCountry(secretkey);


I am using curl for php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'http://www.pfcexpress.com/webservice/APIWebService.asmx/getCountry',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
secretkey => '2add5e13-3b85-45a9-9fcc-4b739de2b1b784342'
)
));

$resp = curl_exec($curl);
$r = mb_convert_encoding($resp,'ISO-8859-1','utf-8');
print_r($r);

curl_close($curl);


But no success.
But getting the following error

[InvalidOperationException: 因 URL 意外地以“/getCountry”结束,请求格式无法识别。]
System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +489333
System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath) +212
System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated) +47
System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +346
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155


I don't understand .Net error

Any help would be highly appreciated.
Thanks.

Answer Source

I solved the issue by moving from CURL to SOAP, as pointed by Ryan above in the comments. We need to use SOAP to connect to .net 'asmx' services

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download