如何从通过API iOS应用程序的HTTP请求 [英] How to make an http request from an iOS app through api

查看:195
本文介绍了如何从通过API iOS应用程序的HTTP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用X code键使一个应用程序,将允许用户通过一个数据库进行搜索。这是goodzer.com数据库,我想知道如何把他们的API为iOS应用程序内的HTTP请求。请什么会有所帮助。

I am using xcode to make an app that will allow the user to search through a database. This is the goodzer.com database and i want to know how to put their API into an http request within an ios app. Please anything will help.

推荐答案

使用框架如 RestKit AFNetworking 。他们都是很容易使用,让您连接到基于REST的API:在任何时间s

Use a framework like RestKit or AFNetworking. They are both really easy to use and lets you connect to RESTful API:s in no time.

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

You will need to sign up for an API key through their website.

通过其数据库搜索会是这个样子(使用AFNetworking):

Searching through their database would look something like this (using 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"
        },
    ...
    ]
}

这篇关于如何从通过API iOS应用程序的HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆