0

何らかの理由で常に がEndpoint not found.表示されますが、ブラウザに入れると完全に動作します。きっと何か悪いことをしている..

- (void)requestLoad:(NSString *)req_udid Age:(NSString *)req_age Gender:(NSString *)req_gender CheckBoxes:(NSString *)req_checkBoxes
{
    NSString *post = [NSString stringWithFormat:@"/UpdatePersonalInterests/%@/%@/%@/%@/0",req_udid, req_age, req_gender, req_checkBoxes];
    NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];

    //set up the request to the website
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

    [request setURL:[NSURL URLWithString:NSLocalizedStringFromTable(@"kServiceURL", @"urls", nil)]];
    [request setHTTPMethod:@"POST"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setValue:[NSString stringWithFormat:@"%d", [postData length]] forHTTPHeaderField:@"Content-Length"];
    [request setHTTPBody:postData];

    NSError *error;
    NSURLResponse *response;

    NSData *urlData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    NSString *result = [[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];

    NSLog(@"%@",result);
}

ありがとう!

4

2 に答える 2

0

So I've managed to do this with NSURLConnection and asynchronous request with this code:

- (void)getIntrests
{
    NSString *req_udid = [PROUtils createOrLoadUserIdentifier];
    NSString *webaddress = [kServiceBaseURL stringByAppendingString:[NSString stringWithFormat:@"/GetPersonalInterestsForUdid/%@",req_udid]];

    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:webaddress] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:20];

    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:
     ^(NSURLResponse* response, NSData* data, NSError* error) {
         NSString* dataString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

         [[NSNotificationCenter defaultCenter] postNotificationName:kGotMediaFromServer object:dataString];

         NSLog(@"Update response completed: %@ with data: %@ error: %@",response,dataString,error);
     }];
}

Hope that it will be useful for someone.

于 2013-01-01T08:25:49.760 に答える
0

カスタム サービス スキームを使用しているようです。Target -> info - URLS Types に登録しましたか? Apple ドキュメントまたはカスタム URL スキームの登録:カスタム URL スキームの実装を参照してください。

于 2012-11-25T16:57:27.090 に答える