在iOS上与SimpleUPC API集成时遇到问题
所以我对这方面还比较陌生,我遇到了一个让我非常困惑的问题。SimpleUPC提供了一个非常简单的API,但JSON请求的格式如下:在iOS上与SimpleUPC API集成时遇到问题,ios,afnetworking,Ios,Afnetworking,所以我对这方面还比较陌生,我遇到了一个让我非常困惑的问题。SimpleUPC提供了一个非常简单的API,但JSON请求的格式如下: { "auth":"Your API Key", "method":"MethodName", "params": { "paramName":"paramValue", "paramName2":"paramValue2", }, "returnFormat":"optional" } 我还从命令行下载了他们的Ruby示例,我已经验证了它的有效性
{
"auth":"Your API Key",
"method":"MethodName",
"params": {
"paramName":"paramValue",
"paramName2":"paramValue2",
},
"returnFormat":"optional"
}
我还从命令行下载了他们的Ruby示例,我已经验证了它的有效性
# Sample API calls using JSON...
host = "api.simpleupc.com"
path = "/v1.php"
# An example query for FetchProductByUPC method
request = {
"auth" => 'Your-API-Key',
"method" => 'FetchProductByUPC',
"params" => {"upc" => '041383096013'}
}
json = request.to_json()
response = Net::HTTP.start(host) { |http|
http.post(path, json, initheader = {'Content-Type' =>'text/json'})
}
output = response.body
puts output
好的,到目前为止还不错。但这里是我的代码,它试图做同样的事情,但我得到的错误抱怨缺少参数
NSDictionary *requestDict = @{@"auth": kSimpleAPIKey, @"method": @"FetchProductByUPC", @"params":@{@"upc": code}};
[[SimpleUPCClient sharedClient] getPath:@""
parameters:requestDict
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Response: %@", responseObject);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[TMReportingHandler handleError:error fatal:NO];
}];
我知道这一定很简单,我做错了,但我想不出来。有人吗?哇,我知道这很简单。原来它期待的是一个帖子,而不是一个GET…我切换了它,它立即工作了 你能发布错误文本吗?