簡體   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