Anfrage mit NSURLRequest

Ich versuche zu tun, um eine app, die eine Datenbank verwendet (eigentlich in meinem localhost), ich habe versucht, mit ASIHTTPRequest aber mit so viel Probleme mit iOS 5 (ich habe gelernt, wie zu verwenden ASIHTTPRequest form : http://www.raywenderlich.com/2965/how-to-write-an-ios-app-that-uses-a-web-service

Nun ich versuche mit der API von Apple : NSURLRequest /NSURLConnection etc,...

Ich lese die Apple-online-Ratgeber und machen dieses ersten code :

- (void)viewDidLoad
{

    [super viewDidLoad];

     //Do any additional setup after loading the view, typically from a nib.



    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL

                                URLWithString:@"http://localhost:8888/testNSURL/index.php"]

                                cachePolicy:NSURLRequestUseProtocolCachePolicy

                                timeoutInterval:60.0];



    [request setValue:@"Hello world !" forKey:@"myVariable"];



    NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];

    if (theConnection) {

        receiveData = [NSMutableData data];   

    }

}

Habe ich noch die benötigten Stellvertreter, der von der API

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data

- (void)connection:(NSURLConnection *)connection

- (void)connectionDidFinishLoading:(NSURLConnection *)connection

Hier ist mein php code :

<?php
if(isset($_REQUEST["myVariable"])) {
    echo $_REQUEST["myVariable"];
}
else    echo '$_REQUEST["myVariable"] not found';
?>

Also, was ist falsch? Wenn ich starte die app, es wird sofort Absturz mit dieser Ausgabe :

**

**> 2012-04-09 22:52:16.630 NSURLconnextion[819:f803] *** Terminating app
> due to uncaught exception 'NSUnknownKeyException', reason:
> '[<NSURLRequest 0x6b32bd0> setValue:forUndefinedKey:]: this class is
> not key value coding-compliant for the key myVariable.'
> *** First throw call stack: (0x13c8022 0x1559cd6 0x13c7ee1 0x9c0022 0x931f6b 0x931edb 0x2d20 0xd9a1e 0x38401 0x38670 0x38836 0x3f72a
> 0x10596 0x11274 0x20183 0x20c38 0x14634 0x12b2ef5 0x139c195 0x1300ff2
> 0x12ff8da 0x12fed84 0x12fec9b 0x10c65 0x12626 0x29dd 0x2945) terminate
> called throwing an exception**

**

Ich denke, es bedeutet, dass irgendwas falsch ist mit dieser Zeile :

[request setValue:@"Hello world !" forKey:@"myVariable"];

Es tatsächlich funktioniert, wenn ich diese Zeile auskommentieren.

Meine Frage ist : Wie sende ich Daten an eine PHP-API, mit NSURLRequest und NSURLConnexion?

Danke für die Hilfe.

P. S. übrigens, ich habe schlechte Kenntnisse über server, PHP ect,...

InformationsquelleAutor Edelweiss | 2012-04-09

Schreibe einen Kommentar