.xml 파일을 API - REST API - BigCommerce에 게시해야합니다. 우리는 그러나 API 행운의 XML 파일을 게시이 PHP 컬 스크립트를 시도.xml 파일을 REST API에 자동으로 게시하십시오.
그것은 상대적으로 기본적인 API를
....<?php
// test XML API POST
$filename = "test.xml";
$handle = fopen($filename, "r");
$XPost = fread($handle, filesize($filename));
fclose($handle);
$url = "https://urlofapi"; // set REST URL
$api_token = "apihashkey";
$xml = urlencode($XPost);
$user_agent = "SoEasy REST API Client 0.1";
// Get the curl session object
$session = curl_init($url);
// set url to post to curl_setopt($session, CURLOPT_URL,$url);
curl_setopt($session, CURLOPT_POST, true); // Tell curl to use HTTP POST;
curl_setopt($session, CURLOPT_POSTFIELDS, $XPost); // Tell curl that this is the body of the POST
curl_setopt($session, CURLOPT_USERPWD, $api_token); // define userpassword api token
curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_ANY); // defining REST basic authentication
curl_setopt($session, CURLOPT_HTTPHEADER, Array("Content-Type: application/xml")); // define header
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false); // ignore ssl cert for debug purposes curl_setopt($session, CURLOPT_USERAGENT, $user_agent); // user agent so the api knows what for some unknown reason
curl_setopt($session, CURLOPT_HEADER, 1); // Tell curl not to return headers, but do return the response
curl_setopt($session, CURLOPT_RETURNTRANSFER, true); // allow redirects curl_setopt($session, CURLOPT_FOLLOWLOCATION, true);
$response = curl_exec($session);
print_r($response);
curl_close($session);
?>
이 지금까지 연결되어 있지만 성공적으로 - 오류가 발생합니다 -
Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/user/public_html/test/new.php on line 7
HTTP/1.1 405 Method Not Allowed Date: Sun, 12 Aug 2012 07:31:11 GMT
Server: Apache Allow: GET, HEAD, OPTIONS
X-BC-ApiLimit-Remaining: 5000 X-BC-Store-Version: 7.3.37
X-Powered-By: PleskLin Transfer-Encoding: chunked Content-Type: application/xml
X-Pad: avoid browser bug 405 This resource does not support the requested method.
Refer to the Allow response header for methods supported by this resource.
우리가 필요로하는 것은 간단하지가 큰 상거래 API에 .xml 파일을 게시 할 것입니다 수 있습니다. .xml은 계정 소프트웨어에서 가져오고 올바른 XML을 생성합니다.
그것의 표준 XML 컬 Bigcommerce REST API를. –