提交 119cfc01 编写于 作者: L libb

add libcurl json

Change-Id: I6da76cc31f63e8af00f51adcb2a19a2c15fd3db7
上级 de66df29
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objects = {
/* Begin PBXBuildFile section */
6586A0D8213246BE00E64AC5 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6586A0D7213246BE00E64AC5 /* main.cpp */; settings = {COMPILER_FLAGS = "-std=c++11"; }; };
6586A0E1213249B400E64AC5 /* libcurl.4.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 6586A0E0213249B400E64AC5 /* libcurl.4.tbd */; };
6586A0E4213249BE00E64AC5 /* libcurl.3.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 6586A0E2213249BE00E64AC5 /* libcurl.3.tbd */; };
6586A0E5213249BE00E64AC5 /* libcurl.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 6586A0E3213249BE00E64AC5 /* libcurl.tbd */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
6586A0D2213246BE00E64AC5 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = /usr/share/man/man1/;
dstSubfolderSpec = 0;
files = (
);
runOnlyForDeploymentPostprocessing = 1;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
6586A0D4213246BE00E64AC5 /* Cpp-Scraper */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "Cpp-Scraper"; sourceTree = BUILT_PRODUCTS_DIR; };
6586A0D7213246BE00E64AC5 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
6586A0E0213249B400E64AC5 /* libcurl.4.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libcurl.4.tbd; path = usr/lib/libcurl.4.tbd; sourceTree = SDKROOT; };
6586A0E2213249BE00E64AC5 /* libcurl.3.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libcurl.3.tbd; path = usr/lib/libcurl.3.tbd; sourceTree = SDKROOT; };
6586A0E3213249BE00E64AC5 /* libcurl.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libcurl.tbd; path = usr/lib/libcurl.tbd; sourceTree = SDKROOT; };
6586A0E621326A7200E64AC5 /* json.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = json.hpp; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
6586A0D1213246BE00E64AC5 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
6586A0E4213249BE00E64AC5 /* libcurl.3.tbd in Frameworks */,
6586A0E5213249BE00E64AC5 /* libcurl.tbd in Frameworks */,
6586A0E1213249B400E64AC5 /* libcurl.4.tbd in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
6586A0CB213246BE00E64AC5 = {
isa = PBXGroup;
children = (
6586A0D6213246BE00E64AC5 /* Cpp-Scraper */,
6586A0D5213246BE00E64AC5 /* Products */,
6586A0DF213249B400E64AC5 /* Frameworks */,
);
sourceTree = "<group>";
};
6586A0D5213246BE00E64AC5 /* Products */ = {
isa = PBXGroup;
children = (
6586A0D4213246BE00E64AC5 /* Cpp-Scraper */,
);
name = Products;
sourceTree = "<group>";
};
6586A0D6213246BE00E64AC5 /* Cpp-Scraper */ = {
isa = PBXGroup;
children = (
6586A0E621326A7200E64AC5 /* json.hpp */,
6586A0D7213246BE00E64AC5 /* main.cpp */,
);
path = "Cpp-Scraper";
sourceTree = "<group>";
};
6586A0DF213249B400E64AC5 /* Frameworks */ = {
isa = PBXGroup;
children = (
6586A0E2213249BE00E64AC5 /* libcurl.3.tbd */,
6586A0E3213249BE00E64AC5 /* libcurl.tbd */,
6586A0E0213249B400E64AC5 /* libcurl.4.tbd */,
);
name = Frameworks;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
6586A0D3213246BE00E64AC5 /* Cpp-Scraper */ = {
isa = PBXNativeTarget;
buildConfigurationList = 6586A0DB213246BE00E64AC5 /* Build configuration list for PBXNativeTarget "Cpp-Scraper" */;
buildPhases = (
6586A0D0213246BE00E64AC5 /* Sources */,
6586A0D1213246BE00E64AC5 /* Frameworks */,
6586A0D2213246BE00E64AC5 /* CopyFiles */,
);
buildRules = (
);
dependencies = (
);
name = "Cpp-Scraper";
productName = Realtor;
productReference = 6586A0D4213246BE00E64AC5 /* Cpp-Scraper */;
productType = "com.apple.product-type.tool";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
6586A0CC213246BE00E64AC5 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0940;
ORGANIZATIONNAME = "Daniel Marchena Parreira";
TargetAttributes = {
6586A0D3213246BE00E64AC5 = {
CreatedOnToolsVersion = 9.4.1;
};
};
};
buildConfigurationList = 6586A0CF213246BE00E64AC5 /* Build configuration list for PBXProject "Cpp-Scraper" */;
compatibilityVersion = "Xcode 9.3";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
);
mainGroup = 6586A0CB213246BE00E64AC5;
productRefGroup = 6586A0D5213246BE00E64AC5 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
6586A0D3213246BE00E64AC5 /* Cpp-Scraper */,
);
};
/* End PBXProject section */
/* Begin PBXSourcesBuildPhase section */
6586A0D0213246BE00E64AC5 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
6586A0D8213246BE00E64AC5 /* main.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
6586A0D9213246BE00E64AC5 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
};
name = Debug;
};
6586A0DA213246BE00E64AC5 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
};
name = Release;
};
6586A0DC213246BE00E64AC5 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
};
6586A0DD213246BE00E64AC5 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
6586A0CF213246BE00E64AC5 /* Build configuration list for PBXProject "Cpp-Scraper" */ = {
isa = XCConfigurationList;
buildConfigurations = (
6586A0D9213246BE00E64AC5 /* Debug */,
6586A0DA213246BE00E64AC5 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
6586A0DB213246BE00E64AC5 /* Build configuration list for PBXNativeTarget "Cpp-Scraper" */ = {
isa = XCConfigurationList;
buildConfigurations = (
6586A0DC213246BE00E64AC5 /* Debug */,
6586A0DD213246BE00E64AC5 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 6586A0CC213246BE00E64AC5 /* Project object */;
}
此差异已折叠。
//
// main.cpp
//
// Created by Daniel Marchena Parreira on 2018-08-25.
// Copyright © 2018 Daniel Marchena Parreira. All rights reserved.
//
#include <string>
#include <sstream>
#include <iostream>
#include <fstream>
#include <thread>
#include <stdio.h>
#include <curl/curl.h>
#include <map>
#include "json.hpp"
std::ofstream dataFile;
bool failedToFetch = false;
size_t WriteCallback(char *contents, size_t size, size_t nmemb, void *userp)
{
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
void dump(const char *text,
FILE *stream, unsigned char *ptr, size_t size)
{
size_t i;
size_t c;
unsigned int width=0x10;
fprintf(stream, "%s, %10.10ld bytes (0x%8.8lx)\n",
text, (long)size, (long)size);
for(i=0; i<size; i+= width) {
fprintf(stream, "%4.4lx: ", (long)i);
/* show hex to the left */
for(c = 0; c < width; c++) {
if(i+c < size)
fprintf(stream, "%02x ", ptr[i+c]);
else
fputs(" ", stream);
}
/* show data on the right */
for(c = 0; (c < width) && (i+c < size); c++) {
char x = (ptr[i+c] >= 0x20 && ptr[i+c] < 0x80) ? ptr[i+c] : '.';
fputc(x, stream);
}
fputc('\n', stream); /* newline */
}
}
int my_trace(CURL *handle, curl_infotype type,
char *data, size_t size,
void *userp)
{
const char *text;
(void)handle; /* prevent compiler warning */
(void)userp;
switch (type) {
case CURLINFO_TEXT:
fprintf(stderr, "== Info: %s", data);
default: /* in case a new one is introduced to shock us */
return 0;
case CURLINFO_HEADER_OUT:
text = "=> Send header";
break;
case CURLINFO_DATA_OUT:
text = "=> Send data";
break;
case CURLINFO_SSL_DATA_OUT:
text = "=> Send SSL data";
break;
case CURLINFO_HEADER_IN:
text = "<= Recv header";
break;
case CURLINFO_DATA_IN:
text = "<= Recv data";
break;
case CURLINFO_SSL_DATA_IN:
text = "<= Recv SSL data";
break;
}
dump(text, stderr, (unsigned char *)data, size);
return 0;
}
void postTask(std::int32_t pages) {
CURL *curl;
CURLcode res;
std::string readBuffer;
std::map <std::string, std::string> postParameters;
/* In windows, this will init the winsock stuff */
curl_global_init(CURL_GLOBAL_ALL);
/* get a curl handle */
curl = curl_easy_init();
if(curl) {
/* First set the URL that is about to receive our POST. This URL can
just as well be a https:// URL if that is what should receive the
data. */
curl_easy_setopt(curl, CURLOPT_URL, "http://119.29.108.104:8080/inweb01/aa.json");
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
/* the DEBUGFUNCTION has no effect until we enable VERBOSE */
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
/* Specify the request callback */
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
/* specify the POST data */
postParameters.emplace("CultureId", "1");
postParameters.emplace("ApplicationId", "1");
postParameters.emplace("RecordsPerPage", "9");
postParameters.emplace("MaximumResults", "9");
postParameters.emplace("PropertySearchTypeId", "1");
postParameters.emplace("TransactionTypeId", "2");
postParameters.emplace("StoreyRange", "0-0");
postParameters.emplace("BedRange", "0-0");
postParameters.emplace("BathRange", "0-0");
postParameters.emplace("LongitudeMin", "-79.41233270339353");
postParameters.emplace("LongitudeMax", "-79.35413949660642");
postParameters.emplace("LatitudeMin", "43.62963286426394");
postParameters.emplace("LatitudeMax", "43.663605932185064");
postParameters.emplace("SortOrder", "A");
postParameters.emplace("SortBy", "1");
postParameters.emplace("viewState", "m");
postParameters.emplace("Longitude", "-79.38323609999999");
postParameters.emplace("Latitude", "43.6466218");
postParameters.emplace("CurrentPage", std::to_string(pages));
postParameters.emplace("ZoomLevel", "14");
postParameters.emplace("PropertyTypeGroupID", "1");
postParameters.emplace("Token", "D6TmfZprLI9Kv5JtoopAH67oXvr3z9weWBbZ0qXajHA=");
postParameters.emplace("GUID", "4483cfc2-fc47-44d5-80c4-5eca6c173ab1");
postParameters.emplace("Version", "6.0");
std::map <std::string, std::string> :: iterator itr;
std::stringstream concatenatePostParams{};
for (itr = postParameters.begin(); itr != postParameters.end(); ++itr)
{
concatenatePostParams << itr->first << '=' << itr->second << '&';
}
std::string paramStr = concatenatePostParams.str();
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, paramStr.c_str());
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
nlohmann::json jsonResponse = nlohmann::json::parse(readBuffer);
/* Check for errors */
if(res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
failedToFetch = true;
}
// std::cout << "Response: " << jsonResponse["ErrorCode"]["Id"] << std::endl;
// if(jsonResponse["ErrorCode"]["Id"] != 200) {
// std::cout << "curl_easy_perform() failed: " << jsonResponse["ErrorCode"]["Description"] << std::endl;
// failedToFetch = true;
// }
dataFile << "Page: " << pages << " c: " << jsonResponse["c"] << std::endl;
}
/* always cleanup */
curl_easy_cleanup(curl);
curl_global_cleanup();
}
int main(void)
{
dataFile.open("data.txt");
std::int32_t pages = 1;
do {
if (failedToFetch) break;
std::thread t1(postTask, pages++);
t1.join();
} while(pages <=10);
dataFile.close();
return 0;
}
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'Realtor' do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
pod "nlohmann_json", '~>3.1.2'
# Pods for Realtor
end
# Cpp Scraper
# Installation
1) Download XCode and open the project
2) Install `Cocoa Pods`: https://cocoapods.org/
* `sudo gem install cocoapods`
3) Install dependencies:
* `pod install`
4) Run the project, enjoy!
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册