繁体   English   中英

如何通过api从iOS应用程序发出http请求

[英]How to make an http request from an iOS app through api

我正在使用xcode制作一个允许用户搜索数据库的应用程序。 这是goodzer.com数据库,我想知道如何将他们的API放入ios应用程序中的http请求。 请帮忙。

使用像RestKitAFNetworking这样的框架。 它们都非常易于使用,并且可以立即连接到RESTful API:s。

您需要通过他们的网站注册API密钥。

搜索他们的数据库看起来像这样(使用AFNetworking):

NSString url = @"http://api.goodzer.com/products/v0.1/search_in_store/?storeId=fAfVfDCd&query=ipad+case&priceRange=20:50&apiKey=<Your_API_key>";
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

这将返回如下内容:

{
    "status": "ok",
    "realtime_availability": true,
    "products_found": 199,
    "products": [
        {
            "id": 1573967503,
            "title": "Harley-Davidson - Envelope Case for Apple iPad, iPad 2 and iPad (3rd Genera ion) - Black",
            "price": 34.99,
            "url": "http://www.bestbuy.com/site/Harley-Davidson+-+Envelope+Case+for+Apple%AE+iPad%AE%2C+iPad+2+and+iPad+(3rd+Generation)+-+Black/5422949.p?id=1218643212507&skuId=5422949&cmp=RMX&ky=2nOYnsgAdnUUUygixM6IZsxTJF3fsquqM",
            "image": "http://img.goodzer.com/peregimator/?size=medium&valign=center&sign=d4e70e4e&image=http%3A//images.bestbuy.com/BestBuy_US/images/products/5422/5422949_sc.jpg"
        },
        {
            "id": 1573970162,
            "title": "Samsonite - Shuttle Case for Apple iPad, iPad 2 and iPad (3rd Generation) - Black/White",
            "price": 39.99,
            "url": "http://www.bestbuy.com/site/Samsonite+-+Shuttle+Case+for+Apple%AE+iPad%AE%2C+iPad+2+and+iPad+(3rd+Generation)+-+Black/White/5763475.p?id=1218692161151&skuId=5763475&cmp=RMX&ky=2nOYnsgAdnUUUygixM6IZsxTJF3fsquqM",
            "image": "http://img.goodzer.com/peregimator/?size=medium&valign=center&sign=9ac997a0&image=http%3A//images.bestbuy.com/BestBuy_US/images/products/5763/5763475_sc.jpg"
        },
    ...
    ]
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM