0
Example:
curl H "Contenttype: application/xml" \
H "AcceptCharset: utf8" \
H "openapikey:50667854bb253d281ce0fe36ebaeebaa" \
api.11street.com.my

How to I authenticate in PHP using curl by using the information above?

After that I want to add product by using curl. Below is my code and it is not working. Website URL: http://lazino.com.my/super/marketplace/11street.php

Reference: enter image description here

<?php

$ch = curl_init();
//COOKIES
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
// Headers
$headers = array();
$headers[] = 'Content-Type: application/xml; charset=utf-8';
$headers[] = 'openapikey:50667854bb253d281ce0fe36ebaeebaa';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// URL
curl_setopt($ch, CURLOPT_URL, 'http://api.11street.my/rest/prodservices/product');

$fields_string = array(
    'selMthdCd' => "01",
    'dispCtgrNo' => "1",
    'prdTypCd' => "01",
    'prdNm' => "TEST product",
    'prdStatCd' => "01",
    'prdWght' => "0.1",
    'minorSelCnYn' => "Y",
    'prdImage01' => "http://staticfs.nexgan.com/images/logo/sallyfashion.com.my_new.jpg",
    'selTermUseYn' => "N",
    'selPrc' => "25.00",
    'prdSelQty' => "0",
    'asDetail' => "test",
    'dlvMthCd' => "01",
    'dlvCstInstBasiCd' => "11",
    'rtngExchDetail' => "Test",
    'suplDtyfrPrdClfCd' => "01"
);
curl_setopt($ch,CURLOPT_POST, sizeof($fields_string));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

$html = curl_exec($ch);
curl_close($ch);

echo $html;

?>
Mister Gan
  • 299
  • 1
  • 4
  • 11

2 Answers2

0

The -H directives are just headers, so you can set them as is described by this SO: PHP cURL custom headers, and then make your GET request using curl_exec. If you're not familiar with HTTP verbs I'd suggest reading this: http://www.restapitutorial.com/lessons/httpmethods.html

Community
  • 1
  • 1
hansod1
  • 314
  • 1
  • 4
0

To authenticate with cURL from PHP:

<?php

$ch = curl_init();
//COOKIES
curl_setopt($ch, CURLOPT_COOKIEFILE, 'path/to/cookies.txt');
// Headers
$headers = array();
$headers[] = 'Content-Type: application/xml; charset=utf-8';
$headers[] = 'openapikey:50667854bb253d281ce0fe36ebaeebaa';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// URL
curl_setopt($ch, CURLOPT_URL, 'api.11street.com.my');

$html = curl_exec($ch);
curl_close($ch);

I think you can find more answers if you just search a little on this website..

UPDATE:

Maybe something like this ?

<?php

$ch = curl_init();
//COOKIES
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
// Headers
$headers = array();
$headers[] = 'Content-Type: application/xml';
$headers[] = 'openapikey:50667854bb253d281ce0fe36ebaeebaa';
// URL
curl_setopt($ch, CURLOPT_URL, 'http://api.11street.my/rest/prodservices/product');

$xml = "<xml>
<selMthdCd>01</selMthdCd>
<dispCtgrNo>1</dispCtgrNo>
<prdTypCd>01</prdTypCd>
<prdNm>TEST PRODUCT</prdNm>
<prdStatCd>01</prdStatCd>
<prdWght>0.1</prdWght>
<minorSelCnYn>Y</minorSelCnYn>
<prdImage01>http://staticfs.nexgan.com/images/logo/sallyfashion.com.my_new.jpg</prdImage01>
<selTermUseYn>N</selTermUseYn>
<selPrc>25.00</selPrc>
<prdSelQty>0</prdSelQty>
<asDetail>test</asDetail>
<dlvMthCd>01</dlvMthCd>
<dlvCstInstBasiCd>11</dlvCstInstBasiCd>
<rtngExchDetail>Test</rtngExchDetail>
<suplDtyfrPrdClfCd>01</suplDtyfrPrdClfCd>
</xml>";

curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $xml );

$html = curl_exec($ch);
curl_close($ch);
echo $html;

What is the server supposed to recieve ?

mihutz
  • 195
  • 1
  • 3
  • 11
  • Hi buddy, your brilliant code just solved the first part of my problem. Now I'm facing new problem, I have problem moving on. Can you refer to the problem above? Thanks! – Mister Gan Mar 07 '16 at 11:00