2016-11-08 42 views
-1

如何從一個API端點對JSON格式的某些數據執行HTTP GET請求並將其POST回另一個API端點。API中的JSON HTTP GET

+1

,如果你想從社區否則你的問題可能被忽略礦石刪除了範圍過寬幫助你應該包括你已經嘗試過的代碼.. – ted

+0

請查看[如何提問](http://stackoverflow.com/help/how-to-ask)並考慮提供[最小,完整和可驗證的示例](http://stackoverflow.com/help/mcve ) – David

+0

提供您的代碼片段或解釋您到目前爲止嘗試過的內容 – captainsac

回答

-1

- (空)的GetRequest {

//Init the NSURLSession with a configuration 
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration]; 
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: nil delegateQueue: [NSOperationQueue mainQueue]]; 

//Create an URLRequest 
NSURL *url = [NSURL URLWithString:@"Your URL"]; 
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url]; 


[urlRequest setHTTPMethod:@"GET"]; 
[urlRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 

//Create task 
NSURLSessionDataTask *dataTask = [defaultSession dataTaskWithRequest:urlRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 
    //Handle your response here 
    // NSLog(@"resultsDictionary is %@",response); 


}]; 

[dataTask resume]; 

}