nsurlrequest

Can't set headers on my WKWebView POST request

吃可爱长大的小学妹 提交于 2019-11-26 19:09:36
问题 I want to do a POST request to my WKWebView but the headers doesn't get set when I monitor the requests with Charles so the request fails. What is wrong here? NSString *post = [NSString stringWithFormat: @"email=%@&password=%@", email, password]; NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; NSString *contentLength = [NSString stringWithFormat:@"%d", postData.length]; NSURL *url = [NSURL URLWithString:@"http://materik.me/endpoint"];

NSData and Uploading Images via POST in iOS

六眼飞鱼酱① 提交于 2019-11-26 18:24:56
I have been combing through the many many posts about uploading images via POST in iOS. Despite the wealth of information on this topic, I cannot manage to correctly upload JPEG data taken from my iPhone Simulator Photo Library. The data, once on the server, is just a huge string of hexidecimal. Shouldn't NSData just be a byte stream? I don't get whats going on with all the hex, or why this code seems to work for everyone else. Here is the code in question: -(void)uploadWithUserLocationString:(NSString*)userLocation{ NSString *urlString = @"http://some.url.com/post"; // set up the form keys

Bad URL when requesting with NSURL

喜欢而已 提交于 2019-11-26 17:48:16
问题 I'm trying to request this kind of URL in iPhone 4.0 SDK (access token slightly modified because you don't really need to see it): https://graph.facebook.com/me?sdk=ios&sdk_version=2&access_token=123902817987|8cb9e8408d2685cef853cd80.9-747882379|UGu5NvcAHiXuGEGzkq&format=json&limit=40&until=1286619821 But I got this message: Failed with error: Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0x9e657a0 {NSUnderlyingError=0x9e656a0 "bad URL", NSLocalizedDescription=bad URL} When I

Swift GET request with parameters

北城以北 提交于 2019-11-26 15:50:25
I'm very new to swift, so I will probably have a lot of faults in my code but what I'm trying to achieve is send a GET request to a localhost server with paramters. More so I'm trying to achieve it given my function take two parameters baseURL:string,params:NSDictionary . I am not sure how to combine those two into the actual URLRequest ? Here is what I have tried so far func sendRequest(url:String,params:NSDictionary){ let urls: NSURL! = NSURL(string:url) var request = NSMutableURLRequest(URL:urls) request.HTTPMethod = "GET" var data:NSData! = NSKeyedArchiver.archivedDataWithRootObject(params

Using AFNetworking and HTTP Basic Authentication

时间秒杀一切 提交于 2019-11-26 15:13:50
问题 The following code successfully connects to my Ruby on Rails API and returns JSON using AFNetworking. What do I need to do to edit this to pass in a username and password so my API can use HTTP Basic Authentication? I've read their documentation, but I am new to both Objective-C and AFNetworking and it isn't currently making sense. NSURL *url = [[NSURL alloc] initWithString:@"http://localhost:3000/tasks.json"]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];

NSURLConnection Using iOS Swift

陌路散爱 提交于 2019-11-26 14:52:22
I am trying to follow this tutorial and connect to a JSON api using Swift and NSURLConnection . I can see that it is hitting the url but the connectionDidFinishLoading does not seem to fire. import UIKit class Remote: NSObject { var host = "http://localhost:3000" var query = String() var data: NSMutableData = NSMutableData() func connect(query:NSString) { self.query = query var url = self.document() var conn = NSURLConnection(request: url, delegate: self, startImmediately: true) } func endpoint() -> NSURL { var query = self.host + self.query return NSURL(string: query) } func document() ->

Append data to a POST NSURLRequest

妖精的绣舞 提交于 2019-11-26 12:06:05
How do you append data to an existing POST NSURLRequest ? I need to add a new parameter userId=2323 . If you don't wish to use 3rd party classes then the following is how you set the post body... NSURL *aUrl = [NSURL URLWithString:@"http://www.apple.com/"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:aUrl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; [request setHTTPMethod:@"POST"]; NSString *postString = @"company=Locassa&quality=AWESOME!"; [request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]]; NSURLConnection *connection= [

How to make POST NSURLRequest with 2 parameters?

好久不见. 提交于 2019-11-26 11:16:38
问题 I want to add 2 parameters to NSURLRequest . Is there a way or should I use AFnetworking? 回答1: It will probably be easier to do if you use AFNetworking. If you have some desire to do it yourself, you can use NSURLSession , but you have to write more code. If you use AFNetworking, it takes care of all of this gory details of serializing the request, differentiating between success and errors, etc.: NSDictionary *params = @{@"firstname": @"John", @"lastname": @"Doe"}; AFHTTPSessionManager

How to send Asynchronous URL Request?

独自空忆成欢 提交于 2019-11-26 07:34:18
问题 I would like to know how do I get a return value 1 or 0 only.... back from an URL request asynchronously. currently I do it in this way: NSString *UTCString = [NSString stringWithFormat:@\"http://web.blah.net/question/CheckQuestions?utc=%0.f\",[lastUTCDate timeIntervalSince1970]]; NSLog(@\"UTC String %@\",UTCString); NSURL *updateDataURL = [NSURL URLWithString:UTCString]; NSString *checkValue = [NSString stringWithContentsOfURL:updateDataURL encoding:NSASCIIStringEncoding error:Nil]; NSLog(@\

NSURLConnection Using iOS Swift

北城以北 提交于 2019-11-26 04:04:38
问题 I am trying to follow this tutorial and connect to a JSON api using Swift and NSURLConnection . I can see that it is hitting the url but the connectionDidFinishLoading does not seem to fire. import UIKit class Remote: NSObject { var host = \"http://localhost:3000\" var query = String() var data: NSMutableData = NSMutableData() func connect(query:NSString) { self.query = query var url = self.document() var conn = NSURLConnection(request: url, delegate: self, startImmediately: true) } func