/    Sign up×
Community /Pin to ProfileBookmark

posting xml to REST web service using php curl

I am totally new to REST web services.I am in need to post some information to the REST web service and get the response which contains the detail of a job posting.The response and request is in xml format.I got some xml code from a developer and he said that he is using this xml to retrieve the details.

The xml code is

[CODE]<soapenv:Envelope xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/” xmlns:ws=”http://ws.mrted.com/”>
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand=”1″ xmlns:wsse=”http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd” xmlns:wsu=”http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd”>
<wsse:UsernameToken wsu:Id=”UsernameToken-1″>
<wsse:Username>PSHFK026203F3VB8MLO798NLD:guest:FO</wsse:Username>
<wsse:Password Type=”http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText”>guest</wsse:Password>
<wsu:Created>2012-07-09T11:35:20.019Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<ws:getAdvertisementById>
<ws:postingTargetId>6337</ws:postingTargetId>
<ws:langCode>UK</ws:langCode>
</ws:getAdvertisementById>
</soapenv:Body>
</soapenv:Envelope>[/CODE]

Now the question is,

1.How this code has been generated?

My php code is,

[code=php]$host = “https://apiurl?api_key=dabc4dvptajdnrhwnqsfxxxx”;
$username = “guest”;
$password = “guest”;
$getjobdetail = ‘<?xml version=”1.0″ encoding=”utf-8″?><getAdvertisementById>
<postingTargetId>6337</postingTargetId>
<langCode>UK</langCode>
</getAdvertisementById>’;

$headers = array();
$headers[] = ‘Accept: application/xml’;
$headers[] = ‘Content-Type: application/xml; charset=UTF-8’;
$process = curl_init($host);
curl_setopt($process, CURLOPT_HTTPHEADER, $headers);
curl_setopt($process, CURLOPT_HEADER, 1);
curl_setopt($process, CURLOPT_USERPWD, $username . “:” . $password);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_POST, 1);
curl_setopt($process, CURLOPT_POSTFIELDS, $getjobdetail);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
$return = curl_exec($process);
echo ‘<pre>’;
print_r($return);
echo ‘</pre>’;
curl_close($process);[/code]

2.Also for the username do I need to use

[code=php]$username = ‘PSHFK026203F3VB8MLO798NLD:guest:FO’[/code]

or just

[code=php]$username = ‘guest’;[/code]

Please suggest how should I proceed and if I am on the right path.Many thanks in advance.

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @raj_2006 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...