Вопрос

Я пытаюсь публиковать данные с iPhone на веб -сервер PHP. Вот мой следующий код:

NSString * fname = @"Brain.";
 NSString * location = @"Germany";

 NSString *post =[NSString stringWithFormat:@"fname=Test&location=Germany"];

 NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

 NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

 NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
 [request setURL:[NSURL URLWithString:@"http://frisbee.brianpagan.net/upload.php"]];
 [request setHTTPMethod:@"POST"];
 [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
 [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
 [request setHTTPBody:postData];

 NSError *error;
 NSURLResponse *response;
 NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
 NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
 NSLog(data);


    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}

Вывод Windows отладчика:

Session started at 2010-03-12 00:03:04 +0100.]
2010-03-12 00:03:05.871 projectx[6357:20b] *** _NSAutoreleaseNoPool(): Object 0x3e061f0 of class NSCFString autoreleased with no pool in place - just leaking
Stack: (0x3226af 0x283e52 0x28e4da 0x23fe 0x238a)
2010-03-12 00:03:05.873 projectx[6357:20b] *** _NSAutoreleaseNoPool(): Object 0x3e07470 of class NSConcreteMutableData autoreleased with no pool in place - just leaking
Stack: (0x3226af 0x283e52 0x2c7a22 0x2428 0x238a)
2010-03-12 00:03:05.873 projectx[6357:20b] *** _NSAutoreleaseNoPool(): Object 0x3e07030 of class NSCFString autoreleased with no pool in place - just leaking
Stack: (0x3226af 0x283e52 0x28e4da 0x2470 0x238a)
2010-03-12 00:03:05.874 projectx[6357:20b] *** _NSAutoreleaseNoPool(): Object 0x3e07710 of class NSMutableURLRequest autoreleased with no pool in place - just leaking
Stack: (0x3226af 0x283e52 0x24bd 0x238a)
2010-03-12 00:03:05.877 projectx[6357:20b] *** _NSAutoreleaseNoPool(): Object 0x3e08e80 of class NSURL autoreleased with no pool in place - just leaking
Stack: (0x3226af 0x283e52 0x2c3891 0x24eb 0x238a)
2010-03-12 00:03:05.878 projectx[6357:20b] *** _NSAutoreleaseNoPool(): Object 0x3e099b0 of class NSCFString autoreleased with no pool in place - just leaking
Stack: (0x3226af 0x283e52 0x37e6d4 0x30a6a9 0x25ca 0x238a)
2010-03-12 00:03:05.880 projectx[6357:20b] *** _NSAutoreleaseNoPool(): Object 0x3e0a9a0 of class NSCFString autoreleased with no pool in place - just leaking
Stack: (0x3226af 0x283e52 0x382b13 0x37e6f0 0x30a6a9 0x25ca 0x238a)
2010-03-12 00:03:05.881 projectx[6357:20b] *** _NSAutoreleaseNoPool(): Object 0x3e0ab30 of class NSCFString autoreleased with no pool in place - just leaking
Stack: (0x3226af 0x283e52 0x37e726 0x30a6a9 0x25ca 0x238a)
2010-03-12 00:03:05.882 projectx[6357:20b] *** _NSAutoreleaseNoPool(): Object 0x3e0ab50 of class NSCFString autoreleased with no pool in place - just leaking
Stack: (0x3226af 0x283e52 0x2df953 0x37e742 0x30a6a9 0x25ca 0x238a)
2010-03-12 00:03:05.884 projectx[6357:20b] *** _NSAutoreleaseNoPool(): Object 0x3e0bd20 of class NSThread autoreleased with no pool in place - just leaking
Stack: (0x3226af 0x283e52 0x2893d4 0x2df65e 0x946ab89e 0x2e06f5 0x2f0411 0x2f02b3 0x2f0237 0x946ab89e 0x2f01e5 0x37e79c 0x30a6a9 0x25ca 0x238a)
2010-03-12 00:03:05.892 projectx[6357:20b] *** _NSAutoreleaseNoPool(): Object 0x3e0fb10 of class NSCFArray autoreleased with no pool in place - just leaking
Stack: (0x3226af 0x283e52 0x2df6b0 0x946ab89e 0x2e06f5 0x2f0411 0x2f02b3 0x2f0237 0x946ab89e 0x2f01e5 0x37e79c 0x30a6a9 0x25ca 0x238a)
2010-03-12 00:03:06.228 projectx[6357:20b] *** _NSAutoreleaseNoPool(): Object 0x3e10b90 of class NSHTTPURLResponse autoreleased with no pool in place - just leaking
Stack: (0x3226af 0x283e52 0x30a72f 0x25ca 0x238a)
2010-03-12 00:03:06.228 projectx[6357:20b] *** _NSAutoreleaseNoPool(): Object 0x3e0ff40 of class NSCFData autoreleased with no pool in place - just leaking
Stack: (0x3226af 0x283e52 0x30a7a3 0x25ca 0x238a)
2010-03-12 00:03:06.229 projectx[6357:20b] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
Welcome Test!<br />
Your location is  Germany .
</body>

Кажется, работает, а затем я создаю простой PHP для прочтения данных POST и вставки их в MySQL:

Welcome <?php echo $_POST["fname"]; ?>!<br />
Your location is  <?php echo $_POST["location"]; ?> .
<?php $con = mysql_connect("localhost","root","");

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
$FirstName =$_POST["fname"]; 
$location =$_POST["location"];

mysql_select_db("test", $con); //what is your database name, 
//Create a table call persons, or u can use any table 
mysql_query("INSERT INTO my_db (firstName, location) 
VALUES ($FirstName,$location)");


mysql_close($con);
?>

Но на странице не отображается мои переменные сообщения. И это не вставлен и в MySQL. Любые идеи? Спасибо

Нет правильного решения

Другие советы

Причина ваших ошибок заключается в том, что вы пытаетесь авторелизировать объекты, прежде чем создать пул авторелиаза.

Похоже, вы поместили свой код в файл main.c. С приложениями для iPhone вы не хотите этого делать, вы хотите поместить свой код в основной класс Delegate и созданные классы. Я бы сначала предложил сделать приложение Hello World, прежде чем попробовать что -то более сложное:

http://www.tuaw.com/2009/04/27/iphone-dev-101-the-hello-world-app/

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top