Tag: http

如何让NSURLSession从服务器返回Content-Length(http头)。 Objective-c,ios

我花了好几个小时试着在这个问题的post中发现的各种想法没有成功。 当我使用curl时,我得到所需的标题 :Content-Length。 这是我最近的尝试(在SO上find的): – (void) trythis { NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession *session = [NSURLSession sessionWithConfiguration:config]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:myURL]; request.HTTPMethod = @"HEAD"; NSURLSessionDownloadTask *uploadTask = [session downloadTaskWithRequest:request completionHandler:^(NSURL *url,NSURLResponse *response,NSError *error) { NSLog(@"handler size: %lld", response.expectedContentLength); NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response; NSDictionary* headers = [httpResponse allHeaderFields]; NSArray *keys = [headers allKeys]; […]

从应用程序启动时轮询外部服务器

我是iOS新手,正在研究在真实设备(iPad)上运行的应用程序。 所以,在视图可见之后,当我在iPad上启动我的应用程序时,应用程序应能够轮询Web服务器或其他内容(无需任何用户交互),并通过HTTP获取一些信息,并基于此信息填写一些文本在应用程序视图中的字段。 你可以让我知道,如果有可能做这样的事情在iOS? 如果是的话,如何和一些样本的代码将不胜感激。 谢谢。

在相同的POST中发送NSData和NSString

我试图按照这种插入imagedata从XCode使用PHP和JSON答案将数据从我的应用程序发送到MySQL数据库,但我很困惑如何添加一个NSString ID引用到POST正文的XCode MySQL数据库。 我们有如下创build获取图像数据的主体: NSMutableData *body = [NSMutableData data]; [body appendData:[[NSString stringWithFormat:@"\r\n–%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithFormat:@"\r\n–%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"image\"; filename=\"imagename.jpg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[NSData dataWithData:imageData]]; [body appendData:[[NSString stringWithFormat:@"\r\n–%@–\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; // setting the body of the post to the reqeust [request setHTTPBody:body]; 我怎样才能在同一篇文章中发送附加信息,例如文本ID?

我如何确定iOS应用程序的HTTP请求的用户代理?

我有一个iOS应用程序,下载一个XML文件使用: NSURL *queryURL = [NSURL URLWithString:query]; NSData *xmlData = [[NSData alloc] initWithContentsOfURL:queryURL]; 打电话给第三方,所以我不控制服务器。 第三方需要知道用户代理是什么(他们正在根据用户代理优化提要) 我的问题是如何确定我的用户代理是什么? 我没有专门设置,并没有find任何文件。

将file upload到OneDrive。 401错误

我正在实施使用BITS协议上传大文件到OneDrive 。 这里是文档 我有以下问题。 经过一段时间的login时,我想创build一个会话,我收到401错误。 这是完整的回应: <NSHTTPURLResponse: 0x7d6ee0f0> { URL: https://cid-da1cedf5484811a9.users.storage.live.com/items/DA1CEDF5484811A9!373/IMG_0003.JPG } { status code: 401, headers { "BITS-Packet-Type" = Ack; "Content-Length" = 0; Date = "Mon, 22 Dec 2014 09:50:22 GMT"; P3P = "CP=\"BUS CUR CONo FIN IVDo ONL OUR PHY SAMo TELo\""; Server = "Microsoft-HTTPAPI/2.0"; "X-AsmVersion" = "UNKNOWN; 19.9.0.0"; "X-ClientErrorCode" = AccessDenied; "X-MSNSERVER" […]

使用AFNetworking 3.0在URL正文中发送JSON数据

我想从我的IOS应用程序发送到我的IOS应用程序的URL 身体的 JSON数据 。我search了许多SO问题,但我找不到我想要的。 如果有人知道如何处理AFNetworking然后请让我知道。谢谢这是我的代码剪发送参数 NSMutableDictionary *parameters = [[NSMutableDictionary alloc]init]; [parameters setValue:@"PY" forKey:@"AppSecret"]; [parameters setValue:@"IOS" forKey:@"login_provider"]; [parameters setValue:_txtemail.text forKey:@"email"]; [parameters setValue:_txtpassword.text forKey:@"password"]; [parameters setValue:@"1" forKey:@"ios_device_id"]; AFHTTPSessionManager *managertwo = [[AFHTTPSessionManager alloc]initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; managertwo.requestSerializer = [AFJSONRequestSerializer serializer]; [managertwo.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [managertwo POST:[NSString stringWithFormat:@"http://capemedics.co.za/Api/user_register/valid_user"] parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { NSLog(@"success! %@",responseObject); NSLog(@"%@",parameters); } […]

如何检查iOS中的Web服务器的状态?

我需要检查Web服务器的状态,具体来说,如果Web服务器返回正确的状态代码200的信息。有什么办法从iOS的Web服务器获取HTTP响应代码?

NSURLConnection和“分块”传输编码

通过其他来源阅读,如: https : //discussions.apple.com/message/7844057#7844057 似乎没有办法使用NSURLConnection读取“分块”传输编码(即没有内容长度)的页面。 任何其他解决方法或其他库可以帮助吗? 更新 :最后通过使用ASIHTTPRequest解决

使用AFNetworking将图像上传到服务器达到了损坏

我一直在努力上传一个图像到服务器,它成功上传,但在服务器端,如果我试图打开它说cannot be displayed because it contains errors的图像, cannot be displayed because it contains errors 。我使用AFNetworking转换成JPEGRepresentation后上传图像。 let uploadManager : AFHTTPSessionManager = AFHTTPSessionManager() uploadManager.responseSerializer = AFHTTPResponseSerializer() as AFHTTPResponseSerializer uploadManager.requestSerializer = AFHTTPRequestSerializer() as AFHTTPRequestSerializer uploadManager.requestSerializer.timeoutInterval = 20 uploadManager.POST(baseURL, parameters: nil, constructingBodyWithBlock: { (formData) -> Void in let selectedImage = self.userImage.image let imageData : NSData = UIImageJPEGRepresentation(selectedImage!, 0.5)! formData.appendPartWithFileData(imageData, […]

iOS:如何获取http连接的源端口

我使用NSURLRequest和NSURLConnection来访问服务器: NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:self.url]; [request setHTTPMethod:@"PROPFIND"]; [request setValue:@"text/xml" forHTTPHeaderField:@"Content-Type"]; … NSURLConnection* conn = [[NSURLConnection alloc] initWithRequest:request delegate:self]; [coon start]; 我知道我们需要一个destination IP和destination port来连接服务器; 问题是: 如何获取和设置我的http连接的source port ? (只是说我需要我的HTTP连接的本地端口); 服务器需要它进行NAT设置。 任何build议将不胜感激。 谢谢。