Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 目标c后置图像和表单数据_Php_Objective C_Post - Fatal编程技术网

Php 目标c后置图像和表单数据

Php 目标c后置图像和表单数据,php,objective-c,post,Php,Objective C,Post,嗨,我正试图从我的iphone应用程序上传一张图片和一些文本数据到我的web服务器上的PHP脚本。我在网上找到了一些上传图像的代码,我添加了一个小代码,我想它可能会上传两个文本字段和数据。我的图片上传很好,但我似乎没有得到我的文本文件。当我从php脚本中回显它时,它显示为空白。我不认为这是我的php脚本的错,因为我所做的只是 $item1=$_POST['item1']; echo$item1 我下面使用的目标c代码正确吗 NSMutableData *body = [NSMutableData

嗨,我正试图从我的iphone应用程序上传一张图片和一些文本数据到我的web服务器上的PHP脚本。我在网上找到了一些上传图像的代码,我添加了一个小代码,我想它可能会上传两个文本字段和数据。我的图片上传很好,但我似乎没有得到我的文本文件。当我从php脚本中回显它时,它显示为空白。我不认为这是我的php脚本的错,因为我所做的只是 $item1=$_POST['item1']; echo$item1

我下面使用的目标c代码正确吗

NSMutableData *body = [NSMutableData data];

[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];

[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"text1\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[text1.text dataUsingEncoding:NSUTF8StringEncoding]];

[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"text2\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[text2.text dataUsingEncoding:NSUTF8StringEncoding]];


[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"userfile\"; filename=\".jpg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];

[body appendData:[[NSString stringWithString:@"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];
试一试

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:connectionURL]];
[request setHTTPMethod:@"POST"];