Tag: networking

如何在PHP中获取或POST多部分数据请求

我正在从iOS发送多部分请求上传图像或文档在服务器上。 我的要求是这样的 UIImage *im = [UIImage imageNamed:@"57X57.png"]; NSData *imageData = UIImageJPEGRepresentation(im, 90); NSString *urlString = @"my URL/upload.php"; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setURL:[NSURL URLWithString:urlString]]; [request setHTTPMethod:@"POST"]; NSString *boundary = @"—————————14737809831466499882746641449"; NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary]; [request addValue:contentType forHTTPHeaderField: @"Content-Type"]; NSString *imgName = @"raj.png"; NSLog(@"image name : %@",imgName); NSMutableData *body = [NSMutableData data]; […]

AFNetworking表单请求(在一个请求中上传多个文件)

我们正在开发一个iOS应用程序。 该应用程序在单个请求中提供单个以及多个file upload选项。 我正在使用AFNetworking单个file upload,哪个工作正常。 现在,我们需要支持多个file upload。 我已经得到了我的HTML代码,实际上从web上传多个文件。我需要从iOS应用程序做同样的事情。 任何人都可以build议我们如何使用AFNetworking做同样的事情? <form method="post" action="upload.php?key=ac2a04cc7b6d4420fa5e5eb1701fb0cc1acf7916&channelid=1" enctype="multipart/form-data"> <label>Title:</label> <input name="title" value="My Video Title" /><br /> <label>Date:</label> <input name="date" value="<?php echo time(); ?>" /><br /> <label>Location:</label> <input name="location" value="Sydney, Australia" /><br /> <textarea name="description">The description of the photo/video goes here</textarea><br /> <input name="file[]" type="file" multiple="multiple" /><br />

如何检查iOS上反应本机应用程序的networkingstream量?

我正在使用最新的React Native(撰写本文时为0.18),并希望检查我的iOS模拟器所提供的networking请求。 使用最新的Xcode“工具”,我得到这个: 。 我在10.11和10.10机器上都得到同样的错误,都使用最新的Xcode。 我也试过使用查尔斯,但它无法拦截stream量。 Wireshark能够看到它,但是我之后的数据是基于SSL的,所以我无法访问它。 作为一个web开发者,理想情况下,我想检查我的chromedebugging器中的networkingstream量,但是我知道在这种环境下这是不可能的,但是仅仅查看原始分组数据对于debugging目的来说是不够友好的。 谁知道这个解决scheme?

如何获得其他设备的主机名在同一个WiFi?

我发现了一些可以扫描本地networking并列出所有设备信息的iOS应用程序。 我不知道如何。 图:

NSMutableURLRequest和“请求身体stream枯竭”错误

我有一个问题与HTTP PUT请求和请求正文从文件stream。 不pipe文件的大小我得到错误“NSURLErrorDomain -1021请求身体stream枯竭” 我知道我可以通过实施该方法来覆盖这个问题: -(NSInputStream*)connection:(NSURLConnection *)connection needNewBodyStream:(NSURLRequest *)request 但这种方法不好,因为它会再次上传整个文件,而40 MB的文件竟然是80 Mb的数据传输。 如果我采取与NSData相同的文件,并设置请求正文工作正常。 我试着发送请求asynchronous并同时在两个同步结果。 这是我的代码,简单,类似于苹果的例子: NSURL *url = [NSURL URLWithString:[self concatenatedURLWithPath:path]]; NSMutableURLRequest *req = [[NSMutableURLRequest alloc] initWithURL:url]; [req setHTTPMethod:@"PUT"]; [req setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; [request setTimeoutInterval:DEFAULT_TIMEOUT]; [req setValue:_contentType forHTTPHeaderField:@"Content-Type"]; NSInputStream *fileStream = [NSInputStream inputStreamWithFileAtPath:_dataStreamLocation]; [req setHTTPBodyStream:fileStream]; _connection = [[NSURLConnection connectionWithRequest:req delegate:self] retain]; 难道我做错了什么? 我错过了什么?

错误域= com.alamofire.error.serialization.response代码= -1011“请求失败:错误的请求(400)

我正在使用AFnetworking库在服务器上发布数据。 以下是我的代码发布数据在服务器上。 – (void) callLoginAPI:(NSDictionary *)dictProfile{ // 1 NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:[dictProfile valueForKey:@"name"], @"username", [dictProfile valueForKey:@"first_name"],@"first_name", [dictProfile valueForKey:@"last_name"],@"last_name", [dictProfile valueForKey:@"email"],@"email", [dictProfile valueForKey:@"birthday"],@"dob", [dictProfile valueForKey:@"gender"],@"gender", [[dictProfile valueForKey:@"location"] valueForKey:@"name"],@"location", [dictProfile valueForKey:@"timezone"],@"timezone", @"",@"language", [NSString stringWithFormat:@"http://graph.facebook.com/%@/picture?type=large",[dictProfile valueForKey:@"id"]],@"profile_pic_url", @"",@"cover_pic_url",nil]; AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.requestSerializer = [AFJSONRequestSerializer serializer]; [manager POST:@"http://10.1.81.35:8000/api/login/" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"JSON: %@", responseObject); […]

链接到伞架

我得到了ios应用程序,我想实施Flurry分析。 导入Flurry和ling libsystem_network.dylib之后 我得到了这个无法解决的问题 ld: cannot link directly with /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/usr/lib/system/libsystem_network.dylib. Link against the umbrella framework 'System.framework' instead. for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation) 在谷歌,我发现在这里和其他一些地方libcommonCrypto.dylib相同的问题: CommonCrypto不是为armv7 iOS开发的 但这并不能帮助我 任何ides? 日Thnx

基于位置跟踪的iOS全职后台服务

我目前正在编写一个应用程序,这个应用程序依赖于位置跟踪并向服务器发送有关位置的数据。 但问题是,它必须全天候运行,目前我每2-3天发生一次随机崩溃。 我做了什么使应用程序在后台运行不断,我把一个NSTimer放在beginBackgroundTaskWithExpirationHandler方法的右边是applicationDidEnterBackground方法。 计时器每分钟执行一次并停止/启动位置服务。 这是一个示例崩溃日志 代码基本如下所示: UIApplication *app = [UIApplication sharedApplication]; __block UIBackgroundTaskIdentifier bgTaskId = 0; bgTaskId = [app beginBackgroundTaskWithExpirationHandler:^{ NSTimer *t = [NSTimer scheduledTimerWithTimeInterval: 1 * 60.0 target: self selector: @selector(onTick) userInfo: nil repeats: YES]; [t fire]; if (bgTaskId != UIBackgroundTaskInvalid){ [app endBackgroundTask: bgTaskId]; bgTaskId = UIBackgroundTaskInvalid; } }]; 我正在使用GCDAsyncSockets进行连接,每次调用的时间约为30秒。 我真的没有想法,可能是什么原因崩溃发生?

禁用Nagle的NSOutputStreamalgorithm

我正在使用MPCF创build一个多人游戏。 您可以使用iPhone控制iPad上的太空船。 我正在经历不同程度的延迟和延迟以及随机时间和间隔的缓冲/暂停,现在已经登陆Apple Technical Q&A NW26论文,讨论禁用Naglealgorithm。 我试了一下,但我的程序不断崩溃,我不明白为什么。 它似乎是CFWriteStreamCopyProperty总是返回NULL。 – (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode { switch (eventCode) { case NSStreamEventOpenCompleted: // Trying to get a handle to the native socket CFSocketNativeHandle rawsock; // This always return NULL CFDataRef socketData = CFWriteStreamCopyProperty((__bridge CFWriteStreamRef)(stream), kCFStreamPropertySocketNativeHandle); // And this row always crash (coz of socketData being NULL i guess) CFDataGetBytes(socketData, […]

确定iPhone是否真正连接到互联网或仅在受限制的热点后面

我在严格识别iPhone的networking访问方面遇到了很多麻烦。 我在StackOverflow上看到过很多像这样的问题,但没有一个能够帮助我。 例如我已经看到这个: 如何检查iOS或OSX上的活动Internet连接? 但是我想知道下面三种情况的发生时间: Wifi 和 3G被禁用 无线或 3G已启用,但没有互联网连接。 这可能是由于3G没有真正的工作,即使它显示在状态栏,或者WiFi是一个热点要求login,让你访问互联网或最后一个场景:WiFi源是本地networking,但不提供任何Internet连接。 一切工作正常 当然,我已经尝试过各种各样的东西,例如: // Allocate a reachability object Reachability* reach = [Reachability reachabilityWithHostname:@"www.google.com"]; // Set the blocks reach.reachableBlock = ^(Reachability*reach) { /* NOT REACHABLE */ dispatch_async(dispatch_get_main_queue(), ^{ iarcSBInternetWarning.visible = NO; }); }; reach.unreachableBlock = ^(Reachability*reach) { /* REACHABLE */ iarcSBInternetWarning.visible = YES; }; // Start […]