0

当调用“cart_customer.addresses”magento API 以从 iOS 下订单时,我收到 HTTP 错误 500。但是,按照此处的示例,它在我由 PHP 编写的测试 api 页面上正常工作。

我不知道为什么从 iOS 调用它时会发生 HTTP 500 错误。下面是我的 Objective-C 源代码:

// Create billing address dictionary
NSMutableDictionary *billingAddressDict = [[[NSMutableDictionary alloc] init] autorelease];

[billingAddressDict setObject:@"billing" forKey:@"mode"];
[billingAddressDict setObject:@"testFirstname" forKey:@"firstname"];
[billingAddressDict setObject:@"testLastname" forKey:@"lastname"];
[billingAddressDict setObject:@"testCompany" forKey:@"company"];
[billingAddressDict setObject:@"testStreet" forKey:@"street"];
[billingAddressDict setObject:@"testCity" forKey:@"city"];
[billingAddressDict setObject:@"testRegion" forKey:@"region"];
[billingAddressDict setObject:@"testPostcode" forKey:@"postcode"];
[billingAddressDict setObject:@"SG" forKey:@"country_id"];
[billingAddressDict setObject:@"0123456789" forKey:@"telephone"];
[billingAddressDict setObject:[NSNumber numberWithInt:0] forKey:@"is_default_shipping"];
[billingAddressDict setObject:[NSNumber numberWithInt:0] forKey:@"is_default_billing"];

// Create shipping address dictionary
NSMutableDictionary *shippingAddressDict = [[[NSMutableDictionary alloc] init] autorelease];

[shippingAddressDict setObject:@"shipping" forKey:@"mode"];
[shippingAddressDict setObject:@"testFirstname" forKey:@"firstname"];
[shippingAddressDict setObject:@"testLastname" forKey:@"lastname"];
[shippingAddressDict setObject:@"testCompany" forKey:@"company"];
[shippingAddressDict setObject:@"testStreet" forKey:@"street"];
[shippingAddressDict setObject:@"testCity" forKey:@"city"];
[shippingAddressDict setObject:@"testRegion" forKey:@"region"];
[shippingAddressDict setObject:@"testPostcode" forKey:@"postcode"];
[shippingAddressDict setObject:@"SG" forKey:@"country_id"];
[shippingAddressDict setObject:@"0123456789" forKey:@"telephone"];
[shippingAddressDict setObject:[NSNumber numberWithInt:0] forKey:@"is_default_shipping"];
[shippingAddressDict setObject:[NSNumber numberWithInt:0] forKey:@"is_default_billing"];
request = [[XMLRPCRequest alloc] initWithURL: url];

NSArray *addressArray = [NSArray arrayWithObjects:shippingAddressDict, billingAddressDict, nil];

params = [NSArray arrayWithObjects:[NSNumber numberWithInt:cartId], addressArray, nil];
[request setMethod:@"call" withParameters:[NSArray arrayWithObjects:sessionId, @"cart_customer.addresses", params, nil]];

response = [self getResponse:request];

这是 getResponse 函数的定义:

- (XMLRPCResponse *)getResponse: (XMLRPCRequest *)request {
    NSError *error = nil;
    XMLRPCResponse *response = [XMLRPCConnection sendSynchronousXMLRPCRequest:request error:&error];

    if (nil != error) {
        NSLog(@"error = %@", [error description]);
        return nil;
    }

    if (nil == response) {
        return nil;
    }

    if ([response isFault]) {
        NSLog(@"Fault with code: %d means: %@", [response.faultCode intValue], response.faultString);
        return nil;
    }

    return [[response retain] autorelease];
}

我使用 Magento 1.5.0.1

重要更新:

当我尝试从字典中删除“电话”时,服务器返回一条验证消息:请输入电话号码。但是,如果我再次将“电话”放在那里,就会出现我向您展示的错误。电话号码有什么问题,我尝试使用新加坡号码(8 位)和美国号码(只有数字,没有空格,没有'-'),但错误仍然存​​在。无论如何,magento提供的官方示例使用了一个虚拟示例:“0123456789”并且它可以工作,所以它也应该对我有用,对吧?

4

0 回答 0