5

我有这段代码,我试图在我的网站上使用 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>abc@abc.com</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>
4

2 回答 2

0

我遇到了类似的问题,这是我在 prestashop 版本 1.6.0.9 上发现的:

1)正如@adrien-g 指出的那样,从更改define('_PS_MODE_DEV_', false);为define('_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>boy@blue.com</email></customer>'
... 
<message><![CDATA[parameter "passwd" required]]></message>
...

3) 然后进行一些实验,例如添加passwdandprestashop标签,最终将引导您走上成功创建客户的道路:

$ 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>boy@blue.com</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>vs 对<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">我玩过的版本没有任何影响。
于 2014-09-15T01:24:12.553 回答
0

“客户”不是一个独立的字段,而是所有其他字段(如名字、姓氏、电子邮件等)的容器。

创建客户的最佳方法是检索空白表并用您的数据填充它:http: //your-prestashop.com/api/customers ?schema=blank

于 2013-08-21T07:11:49.853 回答