开发者

get data from url xcode

i am trying to load the data from an online link that works with php. The link returns an xml. That xml i want to save in the Documents Directory from the iPad. I am trying this:

    NSString *post = @"";
    NSData *postData = [post dataUsingEncoding:NSISOLatin1StringEncoding allowLossyConversion:NO];
    NSMutableURLRequest *urlRequest = [[[NSMutableURLRequest alloc] init] autorelease];
    [urlRequest setURL:[NSURL URLWithString:@"http://www.test.be/tools/xml_nieuwsbrief.php"]];
    [urlRequest setHTTPMethod:@"POST"]; 
    [urlRequest setHTTPBody:postData];


    NSData *urlData; 
    NSURLResponse *response; 
    NSError *error;
    urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error]; 
    if(!urlData) {
        NSLog(@"No connection!");
    }



    NSLog(@"Receive:%d bytes",[urlData length]);
    NSString *aStr = [[[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding]autorelease]; 
    NSLog(@"________%@", aStr);

the string does return - null -, i a have been searching the internet, but does not find anything that can lead me to my problem.

Can开发者_如何学Python someone help me for letting me see what i am doing wrong?

Thanks in advance,

Snowy


I'd check the status code of the response object (change the NSURLResponse object into an NSHTTPURLResponse and you'll have a statusCode property available).

If you are actually getting - null - out of the NSData-response you should probably be looking at the server-side script. Perhaps it is not expecting an empty POST-request?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜