php参数传输

时间:2012-10-23 12:37:20

标签: php post sdk

我尝试将一些文本从我的应用程序发送到php,但不知怎的,我从未收到过文字。这有什么不对?

NSString *name = [[NSString alloc]initWithString: @"Hello World"];
NSString *email = [[NSString alloc]initWithString: @"Ohai2u"];
NSString *urlString = [NSString stringWithFormat:@"http://www.myhosturlxyz.com/tracktxt.php?name=%@ email=%@",
                       [name stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
                       [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

NSURL *url = [[NSURL alloc] initWithString:urlString];

NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];

NSData *urlData;
NSURLResponse *response;
urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:nil];
[url release];

我制作的php是

<?php
    $name = $_REQUEST['name'];
    $email = $_REQUEST['email'];
    $myFile = "tracktxtf.txt";
    $fh = fopen($myFile, 'a') or die("can't open file");
    fwrite($fh, "my posted var is " .$name $email "\n");
    fclose($fh);   
 ?>

1 个答案:

答案 0 :(得分:2)

只是一个疯狂的猜测,但您可能需要在&name=%@之间email=%a,使它成为name=%@&email=%@

或者,您可以尝试使用$_GET['name']$_GET['email']代替REQUEST吗?也许尝试将print_r($_REQUEST, true); print_r($_GET, true);写入调试文件并查看它包含的内容。