您好,我是 iOS 新手,需要向 php 服务器提交图像。为此,我已将图像转换为 base64 格式。并且需要将此 base64 字符串发送到 PHP 服务器。我正在使用的代码是,请帮助我在 ios 中是全新的
// Create your request string with parameter name as defined in PHP file
NSString *myRequestString = [NSString stringWithFormat:@"comment=%@",@"test data"];
// Create Data from request
NSData *myRequestData = [NSData dataWithBytes: [myRequestString UTF8String] length: [myRequestString length]];
request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: @"http://www.sdevices.ru/flashrecorder/speechtotext.php"]];
// set Request Type
[request setHTTPMethod:@"POST"];
// Set content-type
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
// Set Request Body
[request setHTTPBody:myRequestData];
// Now send a request and get Response
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil];
// Log Response
NSString *response = [[NSString alloc] initWithBytes:[returnData bytes] length:[returnData length] encoding:NSUTF8StringEncoding];
NSLog(@"%@",response); // here you get reasponse string
if ([response isEqualToString:@"Speech text!"]) {
UIAlertView *alrt = [[UIAlertView alloc] initWithTitle:@"Flash Recorder" message:@"Text is submitted!" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alrt show];
}