2013-04-10 99 views
5

我有這個代碼,我試圖在我的網站上使用prestashop模式創建一個新客戶。但我一直在響應收到錯誤PrestaShop創建客戶

NSString *xmlPath = [[NSBundle mainBundle] pathForResource:@"Login" ofType:@"xml"]; 

    NSString *xmlStr = [[NSString alloc] initWithContentsOfFile:xmlPath encoding:NSUTF8StringEncoding error:nil]; 

    NSString *encodedurlstring = (__bridge NSString*) CFURLCreateStringByAddingPercentEscapes (NULL, (__bridge CFStringRef) xmlStr, NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]",kCFStringEncodingUTF8); 

    NSString *urlStr = [NSString stringWithFormat:@"http://passkey:@farma-web.it/api/customers/?Xml=%@",encodedurlstring]; 

    NSURL *webURL = [NSURL URLWithString:urlStr]; 
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:webURL]; 

    [request setHTTPMethod:@"POST"]; 
    [request setValue: @"text/xml" forHTTPHeaderField: @"Content-Type"]; 


    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; 
    NSString *response = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding]; 

    NSLog(@"response - %@",response); 

,我已附上XML是

<prestashop> 

<customers> 

<customer>**I DO NOT KNOW WHAT TO WRITE HERE**</customer> 

<email>[email protected]</email> 

<passwd>12344321</passwd> 

<firstname>ABC</firstname> 

<lastname>DEF</lastname> 

</customers> 

</prestashop> 

,我得到的響應

<?xml version="1.0" encoding="UTF-8"?> 
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> 
<errors> 
<error> 
<message><![CDATA[Internal error. To see this error please display the PHP errors.]]></message> 
</error> 
</errors> 
</prestashop> 
+0

我卡住了同樣的問題,如果你解決了這個問題,請分享! – lelloman 2013-06-29 09:38:06

+0

嘿,首先在你的prestashop上啓用調試日誌。爲此,請編輯此文件$(PrestashopDirectory)/config/settings.inc.php並設置define('_ PS_MODE_DEV_',** true **); – 2013-07-02 07:00:44

+0

我仍然無法創建新客戶。我現在正在對它進行一些研究。但是我已經成功完成了地址部分,以防您希望在此API中獲得幫助。 – Swati 2013-07-02 08:06:17

回答

0

我遇到了類似的問題,這裏是我發現的Prestashop上的版本1.6.0.9:

1)由於@adrien -g指出,從define('_PS_MODE_DEV_', false);改爲定義('_ PS_MODE_DEV_',true); http://doc.prestashop.com/display/PS16/Setting+Up+Your+Local+Development+Environment#SettingUpYourLocalDevelopmentEnvironment-Displayingerrormessages

2)接下來你會看到一個像一個與此curl命令模擬更有意義的錯誤:

$ curl -kv https://myprestashop.bitnamiapp.com/prestashop/api/customers?ws_key=secret -d ' 
<?xml version="1.0" encoding="UTF-8"?><customer><lastname>blue</lastname><firstname>boy</firstname><email>[email protected]</email></customer>' 
... 
<message><![CDATA[parameter "passwd" required]]></message> 
... 

3)然後進行一些實驗,如添加的passwdprestashop標籤將最終導致你一個路在這裏你看到客戶成功地創建:

$ curl -kv https://myprestashop.bitnamiapp.com/prestashop/api/customers?ws_key=secret -d ' 
<?xml version="1.0" encoding="UTF-8"?> 
    <prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> 
    <customer><lastname>blue</lastname><firstname>boy</firstname><email>[email protected]</email> 
     <passwd>mysecret</passwd> 
    </customer> 
    </prestashop>' 
... 
<?xml version="1.0" encoding="UTF-8"?> 
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> 
<customer><id><![CDATA[3]]></id>...</customer></prestashop> 
... 

值得注意:

  • 使用<?xml ...><prestashop></prestashop>XML =<?xml ...><prestashop></prestashop>不使我發揮各地的版本有什麼區別。
  • 使用<prestashop><prestashop xmlns:xlink="http://www.w3.org/1999/xlink">在我玩過的版本中沒有任何區別。