nsmutableurlrequest

NSURLRequest setValue: forHTTPHeaderField:@“Authorization” not working

五迷三道 提交于 2019-12-23 00:24:04
问题 I try to make an authenticate call to the twitter API with the Application only Authentication API NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:20.0]; [request setHTTPMethod:@"POST"]; [request setValue:@"application/x-www-form-urlencoded;charset=UTF-8" forHTTPHeaderField:@"Content-Type"]; [request setValue:@"Some App Name" forHTTPHeaderField:@"User-Agent"]; [request setValue

Is it possible to upload a file to server without converting it into NSData?

喜夏-厌秋 提交于 2019-12-22 09:17:57
问题 I am developing an app in which I have to upload a file to server from device, i know how to send file to server using following NSMutableURLRequest , but is it possible to store file to server without converting to NSData ?? I have seen How upload image in to asp.net server without converting into NSData in iPhone this question but didn't find any solution. 回答1: Networks are analogue and computer and devices are digital they not understand what is what for them all the things are digital

Objective c - Send an image over http POST

血红的双手。 提交于 2019-12-21 06:08:03
问题 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]

Objective c - Send an image over http POST

南笙酒味 提交于 2019-12-21 06:07:01
问题 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]

How to print NSMutableURLRequest?

我们两清 提交于 2019-12-18 11:06:37
问题 How to print NSMutableURLRequest using NSLog ? 回答1: .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

cancel NSURLConnection in ios

与世无争的帅哥 提交于 2019-12-18 09:34:12
问题 I am calling webservice on mapView drag/regionChange. I want to keep some delay in the web service calls. So I want that whenever the user drags the map multiple times, all previous web service calls should be cancelled and only last drag web service call should be fired. How do I do this? Following is my code: { .... NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; [request setValue:@"application/json

NSMutableURLRequest not obeying my timeoutInterval

牧云@^-^@ 提交于 2019-12-17 07:07:57
问题 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]; /*

setting content-type overwriting httpbody?

╄→尐↘猪︶ㄣ 提交于 2019-12-14 01:26:04
问题 I'm having a weird issue calling an API from my ios app. I create a post request NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:5.0]; [request setHTTPMethod:@"POST"]; I then create json to send to the request and add it to the body of the request like so: [request setHTTPBody:encodedData]; Finally, I am adding a few cookies which I then set with: NSArray* cookieArray = [NSArray arrayWithObjects:

User-Agent not changing in NSMutableURLRequest

痴心易碎 提交于 2019-12-13 12:29:09
问题 I know there may be several issues about this, but i´m facing a problem when i try to set a new "user agent" for my UIWebView . Here is what i am doing right now: NSURL *myUrl = [NSURL URLWithString:auxUrl]; NSMutableURLRequest *myRequest = [NSMutableURLRequest requestWithURL:myUrl]; NSMutableString *auxUserAgent = [[NSMutableString alloc] initWithString:[myRequest valueForHTTPHeaderField: @"User-Agent"]]; [auxUserAgent appendString:@"(iOS)"]; [myRequest setValue:auxUserAgent

Sending data with POST, issue with character encoding

我的梦境 提交于 2019-12-13 02:15:32
问题 I am having issues with my NSURLRequest and doing a POST whenever the string includes %, for example. On my website, I can see that the encoding is ISO-8859-1,utf-8 for Accept-Charset but for some reason I cannot get the POST to work if it includes "%&$" etc. It seems like it won't encode it with UTF-8 encoding. Am I doing something wrong in the below code? NSData *postData = [credentials dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:NO]; NSString *postLength = [NSString