nsurlconnection

Image(or video) posting to server in Swift

自作多情 提交于 2019-12-07 15:34:35
问题 Hi I am posting json data to server using NSURLSession in swift as below var request = NSMutableURLRequest(URL: NSURL(string: "http://mypath.com")) var session = NSURLSession.sharedSession() request.HTTPMethod = "POST" var params2 :NSDictionary = ["email":"myemail@gmail.com"] var params :NSDictionary = ["function":"forgotPassword", "parameters":params2] var err: NSError? request.HTTPBody = NSJSONSerialization.dataWithJSONObject(params, options: nil, error: &err) request.addValue("application

Synchonous SSL certificate handling on iPhone

泄露秘密 提交于 2019-12-07 14:29:51
问题 I was wondering if anyone can help me understand how to add SSL certificate handling to synchronous connections to a https service. I know how to do this with asynchronous connections but not synchronous. NSString *URLpath = @"https://mydomain.com/"; NSURL *myURL = [[NSURL alloc] initWithString:URLpath]; NSMutableURLRequest *myURLRequest = [NSMutableURLRequest requestWithURL:myURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60]; [myURL release]; [myURLRequest

How to determine the size (in bytes) of a file downloading using NSURLConnection?

时光怂恿深爱的人放手 提交于 2019-12-07 10:50:13
问题 I need to know the size of the file I am downloading (in bytes) into my app using NSURLConnection (GET). Here is my bytes recieved code below if it helps. What I need to know is how to get the filesize in bytes so that I can use it to show a UIProgressView. - (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)data // A delegate method called by the NSURLConnection as data arrives. We just // write the data to the file. { #pragma unused(theConnection) NSInteger

Does disk caching with NSURLRequest and NSURLConnection actually work on the iPhone?

ぐ巨炮叔叔 提交于 2019-12-07 07:30:50
问题 I have a UITableView whose cells contain custom ImageViews that asynchronously load the images from the internet. To load those images I use NSURLRequest and NSURLConnection which works fine. The only problem is that the images are not cached and therefore are downloaded every time they are used. I tried to set the cachePolicy of the NSURLRequest to "NSURLRequestReturnCacheDataElseLoad" with no effect. It seems from the last answer on link that disk caching is not supported with NSURLRequest

NSURLConnection IOS 3G issue

人走茶凉 提交于 2019-12-07 06:00:59
问题 I have used NSURLConnection (asynchronous) in my app which is working fine on wifi (iOS5 & iOS6). But its creating an issue with 3G. When I run my app 3G connection then I dont get any data in my didReceiveData method. I have putted logs in my delegate methods, but while using 3G, The request is getting timed out. What can be the issue. EDIT: On server side -> It shows that my request has been sent to server & server has also sent the response to the client. EDIT 2: The code which I have

HTTPS POST from iPhone using NSURLConnection hangs for certain filesize range

不问归期 提交于 2019-12-07 05:32:07
问题 I'm using NSURLConnection to make an async HTTPS POST to our webservice to upload a jpg. It works fine most of the time. But when the post body is between 196609 and 196868 bytes (inclusive), the connection hangs after the file has been uploaded 100% (didSendBodyData tells me that it's 100% sent). Then after 5 minutes, the connection times out with the message "The network connection was lost." Larger and smaller filesizes work. I've tested this by capping the filesize of the file that I add

Always getting back cached data in NSURLSessionDataTask

放肆的年华 提交于 2019-12-07 04:24:52
问题 I'm facing a very strange issue when using NSURLSessionDataTask to post a JSON request to the server. The first request goes through and I receive the correct JSON response, when I do a second request I'm getting always back the old response and the server never receives the request. Even if I turn on airplane mode the NSURLSessionDataTask does work an I get back the old response again. That's the code I'm using: - (void)getJSONFromURL:(NSURL*)url identifierCode:(NSInteger)code {

NSURLConnection + NSMutableData for file downloads is really slow

瘦欲@ 提交于 2019-12-07 04:24:26
Basically what's happening is that I need to download a whole bunch of files in my app and I've set up a queue of sorts that downloads each file with an NSURLConnection and stores the server response incrementally in an NSMutableData until the download is finished and then writes the whole thing to disk. Here's the relevant parts: - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)_response { response = [_response retain]; if([response expectedContentLength] < 1) { data = [[NSMutableData alloc] init]; } else { data = [[NSMutableData dataWithCapacity:[response

Using a proxy for NSURLConnection

好久不见. 提交于 2019-12-07 02:15:22
问题 Is there any way to get the content of a webfile (namely a .html Document) using a proxy, which is not defined in the system settings? I know that NSURLConnection is the right way to download a web file into a variable and not into a file (for which we should use NSURLDownload), but I don't find a way to use a proxy for it. Are there some unofficial APIs, Libraries or Classes or such I could use for what I want to do? I'm not that pro in Mac Programming, so I'm searching for something more or

使用Swift读取Cookie内容

微笑、不失礼 提交于 2019-12-07 00:10:52
前言 一个http请求中,我们经常会涉及到Get请求的URL Param,POST请求的HTTP Body,Response Json,这些都是一个标准REST API标配的元素。 在一些安全验证的API中,通常会涉及到Cookie。当用户成功登陆后,服务器会在Response Header中写入一个Set-Cookie字段,用来标识用户已经登陆(授权)成功,客户端浏览器接收后会把这个Cookie字段保存在客户端本地。当客户端再次请求API时,就会在Request Header中带上这个Cookie值,告诉服务器:嗨,我已经授权过咯,我的cookie值是xxx,我现在要读取一些信息,请放行~ IOS中的网络请求 一个完整的网络请求,需要先确定Request URL,带上参数,然后发送Request,然后接收Response,处理Response Data。 在IOS中,分别对应如下: //Request URL NSURL //一个完整的Request对象 NSURLRequest //发送请求连接的主要操作者 NSURLConnection //包含返回数据的Response NSURLResponse 下面是一个简单的GET请求代码: let request = NSURLRequest(URL: NSURL(string: "http://devonios.com")!)