nsurlrequest

NSURLConnection returning error instead of response for 401

╄→гoц情女王★ 提交于 2021-02-07 03:40:13
问题 I have a web API that, for a specific request returns status code 200 if everything went ok, and 401 if the user is not logged in based on an Authorization token. Everything works fine if the response status is 200, but doesn't seem to work properly if the response status is 401, returning a connection error with code -1012, while the response is nil. So, the following code: [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data,

NSURLConnection returning error instead of response for 401

你说的曾经没有我的故事 提交于 2021-02-07 03:39:09
问题 I have a web API that, for a specific request returns status code 200 if everything went ok, and 401 if the user is not logged in based on an Authorization token. Everything works fine if the response status is 200, but doesn't seem to work properly if the response status is 401, returning a connection error with code -1012, while the response is nil. So, the following code: [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data,

How to handle “too many HTTP redirects” Error

梦想的初衷 提交于 2020-08-11 08:40:50
问题 This issue comes when i load website into webview of my cocoa application. my issue description: Error Domain=NSURLErrorDomain Code=-1007 "too many HTTP redirects" UserInfo=0x18d17d56{NSErrorFailingURLStringKey=URLHERE, NSErrorFailingURLKey=URLHERE,NSLocalizedDescription=too many HTTP redirects} why this error comes how to handle it i go though following links but does't help me Too many HTTP redirects "too many HTTP redirects" while using Alamofire Upload Multipart Form Data too many HTTP

Swift - Reusable URL Request with Delegates

孤人 提交于 2020-03-23 11:59:05
问题 Hi I'm new to Swift and I am trying to create a reusable generic Download Manager for URL Request that can be reused throughout my project in different View Controllers or reused within the same VC for a different URL Request calls. The problem that I have is how do I pass the Data Type from the Request into the Download Manager and then return the Downloaded Data back to the VC with the corresponding Data Type. I am able to pass the Data Type in a call to downloadRequest but I can't figure

POST URLRequest doesn't work in Swift 4

旧时模样 提交于 2020-01-24 01:36:06
问题 I want to use HTTP request to post an image on Imgur. I used Postman first to make sure my API logic is correct. Here is my setting for Postman ( myid is client id): This request succeeded, but the request failed in Swift with URLRequest and URLSession (Status Code: 400). var request = URLRequest(url: self.uploadURL!) request.httpMethod = "POST" request.setValue("Client-ID " + myid, forHTTPHeaderField: "Authorization") let data = "image=\(base64String)&type=base64".data(using: .utf8,

How I know the the posting data goes correctly

旧城冷巷雨未停 提交于 2020-01-22 01:39:07
问题 -(IBAction)clicked:(id)sender{ NSString *CIDString = cID.text; NSURL *url = [NSURL URLWithString:@"http://localhost:8080/test/?"]; NSString *postData = [NSString stringWithFormat:@"companyID=%@",CIDString]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[url standardizedURL] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60]; [request setHTTPMethod:@"POST"]; [request setValue:@"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@