nsurlrequest

NSURLRequest Upload Multiple Files

别等时光非礼了梦想. 提交于 2019-11-28 06:33:54
问题 I'm trying to upload multiple files to a server using a POST request, but for some reason, only one file is submitted. I suspect I'm doing something wrong with the boundary, but I'm not sure where... What's wrong with my code? [_serverRequest setHTTPMethod:@"POST"]; NSString *_boundary = @"14737809831466499882746641449"; NSString *_contentType = [NSString stringWithFormat:@"multipart/form-data; charset=UTF-8; boundary=%@",_boundary]; [_serverRequest setValue:_contentType forHTTPHeaderField:@

Change User-Agent

旧巷老猫 提交于 2019-11-28 06:26:42
问题 How can I change in my WebView the default string of User-Agent? @IBOutlet weak var myWbView: UIWebView! let myURL = NSURL(string: "http://http://web-example") let myURLRequest:NSURLRequest = NSURLRequest(URL: myURL!) myWbView.loadRequest(myURLRequest) 回答1: If you want to set User-Agent HTTP header for your request that is going to be used for Web-view loading, let userAgent = "Custom User Agent"; let myURL = NSURL(string: "http://http://web-example") let myURLRequest:NSURLRequest =

NSURLConnection NSURLRequest proxy for asynchronous web service calls

痞子三分冷 提交于 2019-11-28 06:07:00
I have multiple views which make the same NSURLRequest/NSURLConnection request . Ideally, in order to get some code reuse, I'd like to have some sort of a "proxy" which does all the underlying work of creating/executing the (asynchronous) request/connection, setting up all the delegate methods, etc., so I don't have to copy all those NSURLConnection delegate method handlers in each view. First of all, is this design approach reasonable? Second, how would I go about doing something like that? For a little background info, I attempted this and got it to "work", however, it doesn't appear to be

Reliable way to compare two NSURL or one NSURL and an NSString?

梦想与她 提交于 2019-11-28 05:57:24
I recently had a problem when comparing two NSURLs and compare one NSURL with an NSString(which is a URL address), the situation is I got an NSURLRequest from somewhere, I may or may not know the URL address it points to, and I have an URL NSString, say "http://m.google.com", now I need to check if the URL in that NSURLRequest is the same as the URL string I had: [[request.URL.absoluteString lowercaseString] isEqualToString: [self.myAddress lowercaseString]]; this returns NO as the absoluteString gives me "http://m.google.com/" whereas my string is "http://m.google.com" without a slash in the

Can't set headers on my WKWebView POST request

谁都会走 提交于 2019-11-28 03:59:56
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"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; [request setHTTPMethod:@"POST"]; [request

NSURLRequest cannot handle HTTP body when method is not POST?

旧街凉风 提交于 2019-11-27 23:38:02
问题 Whenever I set a body on a mutable request with the method set to anything other than POST, the body is not included in the request and I get a kCFErrorDomainCFNetwork error 303 (kCFErrorHTTPParseFailure) when the server replies. Changing the method to POST is all it takes for the request to go through with no error. Is there any way to attach a body to other methods, or are we stuck with POST for everything? This is the submission code: NSMutableURLRequest *req = [NSMutableURLRequest

NSURLConnection/NSURLRequest gzip support

被刻印的时光 ゝ 提交于 2019-11-27 18:21:05
Does anyone knows if NSURLConnection/NSURLRequest have support for gzip requests. If does, can you provide more information? ax. although it does not seem to be documented , there is evidence that NSURLConnection does have transparent gzip support. meaning that if the server supports gzip encoding, and your request has an Accept-Encoding header containing gzip *, the server will send a gzipped response, which NSURLConnection will automatically decode. * NSURLRequest might add that header by default. if not, you have to add it manually like so: [urlReq setValue:@"gzip" forHTTPHeaderField:@

Get cookies from NSHTTPURLResponse

谁都会走 提交于 2019-11-27 18:14:28
问题 I've an extremely weird problem, I'm requesting a URL and I want to get the cookies from it, I've used this way to get the cookies: - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)response; NSDictionary *fields = [HTTPResponse allHeaderFields]; NSString *cookie = [fields valueForKey:"Set-Cookie"]; } BUT the cookies is not complete, there is some field is missing, I've checked it on PostMan,

NSURLConnection leak?

左心房为你撑大大i 提交于 2019-11-27 11:22:20
问题 i have set up a nsurl which grabs the data from http. when i run instrument, it says i have a leak NSFNetwork object. and how do i release theConnection in (void)ButtonClicked? or it will be release later on? - (void)ButtonClicked { NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:KmlUrl] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0f]; NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; if

How do I make HTTP post request for getting JSON object in response for iPhone application?

隐身守侯 提交于 2019-11-27 11:21:38
问题 I've a web service running on server which return data either in XML format or JSON format. I wanted to request a JSON format but using HTTP Post method. any help greatly appreciated. thanks in advance. 回答1: This is the code which work for JSON post request, TouchJSON Framework is used for parsing the JSON, thanks 'schwa'. NSArray *keys = [NSArray arrayWithObjects:@"username", @"password", @"preference", @"uid", nil]; NSArray *objects = [NSArray arrayWithObjects:@"accuser", @"accpass", @"abc