nsmutableurlrequest

Objective c - Send an image over http POST

心已入冬 提交于 2019-12-03 20:29:57
I'm trying to understand how to send an image with http POST and my current client-server protocol design. All the messages from client to server looks like the example below, there is a cmd string with parameter cmd and some more relevant parameters for the command. For example this is how i send a text message to the server: - (void)sendMessagesWithText:(NSString *)text fromUser:(NSString *)userId { NSString *url = SERVER_URL; NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; [request setURL:[NSURL URLWithString:url]]; [request setHTTPMethod:@"POST"];

NSURLCache - Disk caching for GET request with parameters not working

微笑、不失礼 提交于 2019-12-03 20:08:34
I'm trying to cache some HTTP requests to disk using NSURLCache. After doing some tests with AFNetworking and not working, I created a simple example using NSURLRequest. I initialize the cache on the AppDelegate like this, setting the memory size to 0, forcing it to go always to Disk: NSUInteger sz = 1024*1024*20; NSURLCache *cache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:sz diskPath:nil]; [NSURLCache setSharedURLCache:cache]; I use the following code to store the response: NSURLCache *urlCache = [NSURLCache sharedURLCache]; NSString *urlString = @"http://localhost:8000

Request to web service over SSL

ⅰ亾dé卋堺 提交于 2019-12-03 13:00:48
i am struggling to request web service using https. I am getting this kind of error: An error occured : The certificate for this server is invalid. You might be connecting to a server that is pretending to be “SERVER_ADDRESS” which could put your confidential information at risk. I am not using NSUrlConnectionDelegate. Here is my method: - (void)sendRequestWithUrl:(NSURL*)url block:(void (^)(NSDictionary *dict, NSError *error)) block{ NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; [request setHTTPMethod:@"POST"]; [[NSRunLoop currentRunLoop] runMode

How can i upload file and other parameter using NSURLConnection

荒凉一梦 提交于 2019-12-01 14:19:29
I am using NSURLConnection to send same data ( NSString ) to the server and i would like to add with them an image or a file so what's the value of the content type? Encoding - (NSData *)encodingData:(NSMutableDictionary *)dictionary { NSMutableArray *arrayPosts = [[NSMutableArray alloc] init]; [dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { NSString *encodedKey = [key stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSString *encodedValue = [obj stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; [arrayPosts addObject:[NSString

How can i upload file and other parameter using NSURLConnection

徘徊边缘 提交于 2019-12-01 10:13:19
问题 I am using NSURLConnection to send same data ( NSString ) to the server and i would like to add with them an image or a file so what's the value of the content type? Encoding - (NSData *)encodingData:(NSMutableDictionary *)dictionary { NSMutableArray *arrayPosts = [[NSMutableArray alloc] init]; [dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { NSString *encodedKey = [key stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSString *encodedValue = [obj

NSMutableURLRequest and “request body stream exhausted” error

﹥>﹥吖頭↗ 提交于 2019-12-01 07:47:57
I have a problem with http PUT request and request body as stream from file. No matter what the size of the file i get error "NSURLErrorDomain -1021 request body stream exhausted" I know i can override this problem by implementing the method: -(NSInputStream*)connection:(NSURLConnection *)connection needNewBodyStream:(NSURLRequest *)request but this approach is not good as it will upload the whole file again, and 40 MB of file turns out to be 80 Mb of data transfer. if i take the same file as NSData and set the request body it works fine. I tried sending the request Async and sync same result

NSMutableURLRequest and “request body stream exhausted” error

放肆的年华 提交于 2019-12-01 04:31:44
问题 I have a problem with http PUT request and request body as stream from file. No matter what the size of the file i get error "NSURLErrorDomain -1021 request body stream exhausted" I know i can override this problem by implementing the method: -(NSInputStream*)connection:(NSURLConnection *)connection needNewBodyStream:(NSURLRequest *)request but this approach is not good as it will upload the whole file again, and 40 MB of file turns out to be 80 Mb of data transfer. if i take the same file as

How to print NSMutableURLRequest?

走远了吗. 提交于 2019-11-30 01:18:46
How to print NSMutableURLRequest using NSLog ? visakh7 .allHTTPHeaderFields returns a dictionary with the header content: NSLog(@"%@", [request allHTTPHeaderFields]); // { // "Accept-Language" = "en;q=1"; // "Content-Length" = 190706; // "Content-Type" = "multipart/form-data; boundary=Boundary+D90A259975186725"; // "User-Agent" = "..."; // } Or for specific field: NSString *field = @"Content-Type"; NSLog(@"%@",[request valueForHTTPHeaderField:field]); // multipart/form-data; boundary=Boundary+D90A259975186725 Did you try with NSLog(@" %@", myMutableURLRequest); 来源: https://stackoverflow.com

Sending a POST request from Cocoa to Tumblr

末鹿安然 提交于 2019-11-27 07:09:05
This code snippet isn't working, I'm getting an "Authentication Failed." response from the server. Any ideas? NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString:@"http://www.tumblr.com/api/write"]]; [request setHTTPMethod:@"POST"]; [request addValue:_tumblrLogin forHTTPHeaderField:@"email"]; [request addValue:_tumblrPassword forHTTPHeaderField:@"password"]; [request addValue:@"regular" forHTTPHeaderField:@"type"]; [request addValue:@"theTitle" forHTTPHeaderField:@"title"]; [request addValue:@"theBody" forHTTPHeaderField:@"body"]; NSLog(@"Tumblr Login:

NSMutableURLRequest not obeying my timeoutInterval

假装没事ソ 提交于 2019-11-27 03:03:48
I'm POST'ing a small image, so i'd like the timeout interval to be short. If the image doesn't send in a few seconds, it's probably never going to send. For some unknown reason my NSURLConnection is never failing, no matter how short I set the timeoutInterval . // Create the URL request NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.tumblr.com/api/write"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:0.00000001]; /* Populate the request, this part works fine */ [NSURLConnection connectionWithRequest:request delegate