当调用“cart_customer.addresses”magento API以便从iOS下订单时,我得到了HTTP错误500.但是,它在PHP编写的测试api页面上正常工作,遵循示例here 。
我不知道为什么从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”并且它有效,所以它也适用于我,对吗?