post 上的无效索引通过 ASync NSURLConnection
Invalid Index on post via ASync NSURLConnection
Im posting 数据从 IOS 到 php 脚本。自从从同步请求更改为异步请求后,我一直无法上传。
好的,我的网络服务器日志中出现以下错误
[Sat Nov 28 13:18:56 2015] [error] [client 80.6.199.219:38875] AH01215: PHP Deprecated: Comments starting with '#' are deprecated in public_html/iphone2/php.ini on line 1 in Unknown on line 0: public_html/iphone2/UploadImage.php
[Sat Nov 28 13:18:56 2015] [error] [client 80.6.199.219:38875] AH01215: PHP Notice: Undefined index: user_id in public_html/iphone2/UploadImage.php on line 8: public_html/iphone2/UploadImage.php
[Sat Nov 28 13:18:56 2015] [error] [client 80.6.199.219:38875] AH01215: PHP Notice: Undefined index: RequestID in public_html/iphone2/UploadImage.php on line 9: public_html/iphone2/UploadImage.php
[Sat Nov 28 13:18:56 2015] [error] [client 80.6.199.219:38875] AH01215: PHP Notice: Undefined index: base64 in public_html/iphone2/UploadImage.php on line 10: public_html/iphone2/UploadImage.php
500kgiveaway.co.uk [Sat Nov 28 13:18:56 2015] [error] [client 80.6.199.219:38875] AH01215: PHP Notice: Undefined index: base64_thumb in ublic_html/iphone2/UploadImage.php on line 11: public_html/iphone2/UploadImage.php
[Sat Nov 28 13:18:56 2015] [error] [client 80.6.199.219:38875] AH01215: PHP Notice: Undefined index: ImageName in public_html/iphone2/UploadImage.php on line 14: public_html/iphone2/UploadImage.php
[Sat Nov 28 13:18:56 2015] [error] [client 80.6.199.219:38875] AH01215: PHP Notice: Undefined index: ImageName in /home/sites/500kgiveaway.co.uk/public_html/iphone2/UploadImage.php on line 13: /home/sites/500kgiveaway.co.uk/public_html/iphone2/UploadImage.php
500kgiveaway.co.uk [Sat Nov 28 13:18:56 2015] [error] [client 80.6.199.219:38875] AH01215: PHP Notice: Undefined index: ImageName in /home/sites/500kgiveaway.co.uk/public_html/iphone2/UploadImage.php on line 30: /home/sites/500kgiveaway.co.uk/public_html/iphone2/UploadImage.php
500kgiveaway.co.uk [Sat Nov 28 13:18:56 2015] [error] [client 80.6.199.219:38875] AH01215: PHP Notice: Undefined index: ImageName in public_html/iphone2/UploadImage.php on line 42: public_html/iphone2/UploadImage.php
500kgiveaway.co.uk [Sat Nov 28 13:18:56 2015] [error] [client 80.6.199.219:38875] AH01215: PHP Warning: file_put_contents(upload/images/): failed to open stream: Is a directory in public_html/iphone2/UploadImage.php on line 42: public_html/iphone2/UploadImage.php
这是发送 post 请求的代码
- (void)uploadToServer:(NSString *)base64Large thumb:(NSString *)base64Thumb {
NSString *poststring = @"";
long currentTime = (long)(NSTimeInterval)([[NSDate date] timeIntervalSince1970]);
NSString *currentTimeString = [NSString stringWithFormat:@"%ld",currentTime];
NSString *fileName = [currentTimeString stringByAppendingString:@".jpg"];
NSString *postImageName = @"ImageName=%imagename%&";
postImageName =[postImageName stringByReplacingOccurrencesOfString:@"%imagename%" withString:fileName];
poststring = [poststring stringByAppendingString:postImageName];
NSString *postUserID = @"user_id=%UserID%&";
postUserID =[postUserID stringByReplacingOccurrencesOfString:@"%UserID%" withString:@"2"];
poststring = [poststring stringByAppendingString:postUserID];
NSString *postRequestListID = @"RequestID=%RLID%&";
postRequestListID =[postRequestListID stringByReplacingOccurrencesOfString:@"%RLID%" withString:self.golbalRequestListID];
poststring = [poststring stringByAppendingString:postRequestListID];
NSString *postBase64 = @"base64=%B64%&";
postBase64 =[postBase64 stringByReplacingOccurrencesOfString:@"%B64%" withString:base64Large];
postBase64 = [postBase64 stringByReplacingOccurrencesOfString:@"+" withString:@"%2B"];
poststring = [poststring stringByAppendingString:postBase64];
NSString *postBase64thumb = @"base64_thumb=%B64T%&";
postBase64thumb =[postBase64thumb stringByReplacingOccurrencesOfString:@"%B64T%" withString:base64Thumb];
postBase64thumb = [postBase64thumb stringByReplacingOccurrencesOfString:@"+" withString:@"%2B"];
poststring = [poststring stringByAppendingString:postBase64thumb];
//create the request
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"iphone2/UploadImage.php"]];
//Specify that it will be a post request
request.HTTPMethod = @"POST";
//This is how we set header fields
[request setValue:@"application/xml: charset=utf-8" forHTTPHeaderField:@"Content-Type"];
//convert your data and set your requests httpbody property
NSData *requestBodyData = [poststring dataUsingEncoding:NSUTF8StringEncoding];
request.HTTPBody = requestBodyData;
//create url connection and fire request
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
}
post 请求包含一些数据库条目和 2 张 base64 图像(1 张全尺寸图像约 5-7mb 和缩略图版本 (1-2mb))
正如我之前所说,使用 Sync 方法时效果很好。
我在 xcode 中没有收到任何错误,当我监视 didSendBodyData 方法时,我可以看到应用正在发送数据。
我认为这可能是 post 请求的问题,但是我找不到检查它是否有效的方法。我还认为我发送的数据量可能有问题,所以我将 post 限制增加到 20MB
老实说,我想不出还有什么问题。
原来是header字段的值有问题
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
影响取自以下post
我希望这对其他人有帮助
Im posting 数据从 IOS 到 php 脚本。自从从同步请求更改为异步请求后,我一直无法上传。
好的,我的网络服务器日志中出现以下错误
[Sat Nov 28 13:18:56 2015] [error] [client 80.6.199.219:38875] AH01215: PHP Deprecated: Comments starting with '#' are deprecated in public_html/iphone2/php.ini on line 1 in Unknown on line 0: public_html/iphone2/UploadImage.php
[Sat Nov 28 13:18:56 2015] [error] [client 80.6.199.219:38875] AH01215: PHP Notice: Undefined index: user_id in public_html/iphone2/UploadImage.php on line 8: public_html/iphone2/UploadImage.php
[Sat Nov 28 13:18:56 2015] [error] [client 80.6.199.219:38875] AH01215: PHP Notice: Undefined index: RequestID in public_html/iphone2/UploadImage.php on line 9: public_html/iphone2/UploadImage.php
[Sat Nov 28 13:18:56 2015] [error] [client 80.6.199.219:38875] AH01215: PHP Notice: Undefined index: base64 in public_html/iphone2/UploadImage.php on line 10: public_html/iphone2/UploadImage.php
500kgiveaway.co.uk [Sat Nov 28 13:18:56 2015] [error] [client 80.6.199.219:38875] AH01215: PHP Notice: Undefined index: base64_thumb in ublic_html/iphone2/UploadImage.php on line 11: public_html/iphone2/UploadImage.php
[Sat Nov 28 13:18:56 2015] [error] [client 80.6.199.219:38875] AH01215: PHP Notice: Undefined index: ImageName in public_html/iphone2/UploadImage.php on line 14: public_html/iphone2/UploadImage.php
[Sat Nov 28 13:18:56 2015] [error] [client 80.6.199.219:38875] AH01215: PHP Notice: Undefined index: ImageName in /home/sites/500kgiveaway.co.uk/public_html/iphone2/UploadImage.php on line 13: /home/sites/500kgiveaway.co.uk/public_html/iphone2/UploadImage.php
500kgiveaway.co.uk [Sat Nov 28 13:18:56 2015] [error] [client 80.6.199.219:38875] AH01215: PHP Notice: Undefined index: ImageName in /home/sites/500kgiveaway.co.uk/public_html/iphone2/UploadImage.php on line 30: /home/sites/500kgiveaway.co.uk/public_html/iphone2/UploadImage.php
500kgiveaway.co.uk [Sat Nov 28 13:18:56 2015] [error] [client 80.6.199.219:38875] AH01215: PHP Notice: Undefined index: ImageName in public_html/iphone2/UploadImage.php on line 42: public_html/iphone2/UploadImage.php
500kgiveaway.co.uk [Sat Nov 28 13:18:56 2015] [error] [client 80.6.199.219:38875] AH01215: PHP Warning: file_put_contents(upload/images/): failed to open stream: Is a directory in public_html/iphone2/UploadImage.php on line 42: public_html/iphone2/UploadImage.php
这是发送 post 请求的代码
- (void)uploadToServer:(NSString *)base64Large thumb:(NSString *)base64Thumb {
NSString *poststring = @"";
long currentTime = (long)(NSTimeInterval)([[NSDate date] timeIntervalSince1970]);
NSString *currentTimeString = [NSString stringWithFormat:@"%ld",currentTime];
NSString *fileName = [currentTimeString stringByAppendingString:@".jpg"];
NSString *postImageName = @"ImageName=%imagename%&";
postImageName =[postImageName stringByReplacingOccurrencesOfString:@"%imagename%" withString:fileName];
poststring = [poststring stringByAppendingString:postImageName];
NSString *postUserID = @"user_id=%UserID%&";
postUserID =[postUserID stringByReplacingOccurrencesOfString:@"%UserID%" withString:@"2"];
poststring = [poststring stringByAppendingString:postUserID];
NSString *postRequestListID = @"RequestID=%RLID%&";
postRequestListID =[postRequestListID stringByReplacingOccurrencesOfString:@"%RLID%" withString:self.golbalRequestListID];
poststring = [poststring stringByAppendingString:postRequestListID];
NSString *postBase64 = @"base64=%B64%&";
postBase64 =[postBase64 stringByReplacingOccurrencesOfString:@"%B64%" withString:base64Large];
postBase64 = [postBase64 stringByReplacingOccurrencesOfString:@"+" withString:@"%2B"];
poststring = [poststring stringByAppendingString:postBase64];
NSString *postBase64thumb = @"base64_thumb=%B64T%&";
postBase64thumb =[postBase64thumb stringByReplacingOccurrencesOfString:@"%B64T%" withString:base64Thumb];
postBase64thumb = [postBase64thumb stringByReplacingOccurrencesOfString:@"+" withString:@"%2B"];
poststring = [poststring stringByAppendingString:postBase64thumb];
//create the request
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"iphone2/UploadImage.php"]];
//Specify that it will be a post request
request.HTTPMethod = @"POST";
//This is how we set header fields
[request setValue:@"application/xml: charset=utf-8" forHTTPHeaderField:@"Content-Type"];
//convert your data and set your requests httpbody property
NSData *requestBodyData = [poststring dataUsingEncoding:NSUTF8StringEncoding];
request.HTTPBody = requestBodyData;
//create url connection and fire request
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
}
post 请求包含一些数据库条目和 2 张 base64 图像(1 张全尺寸图像约 5-7mb 和缩略图版本 (1-2mb))
正如我之前所说,使用 Sync 方法时效果很好。
我在 xcode 中没有收到任何错误,当我监视 didSendBodyData 方法时,我可以看到应用正在发送数据。
我认为这可能是 post 请求的问题,但是我找不到检查它是否有效的方法。我还认为我发送的数据量可能有问题,所以我将 post 限制增加到 20MB
老实说,我想不出还有什么问题。
原来是header字段的值有问题
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
影响取自以下post
我希望这对其他人有帮助