2012-05-08 8 views
1

これはかなり混乱しています。私は、次に入れた場合:NSURLRequestのURL文字列を生成できません

NSString *LoginURLString = [NSString stringWithFormat:@"http://dispatch.americantaxi.com:8080/AT/servlet/OnlineOrderServices?command=retrieveCustomerCommonPlaces&customerId=13242134"]; 
//NSLog output: http://dispatch.americantaxi.com:8080/AT/servlet/OnlineOrderServices?command=retrieveCustomerCommonPlaces&customerId=2314084 

そして、URLリクエストでこれを使用し、それが正常に動作しますが、私はこれを動的にする必要があるので、私はそれが次を使用して、新しいユーザーIDとURLの文字列を連結してい:ここでは

NSString *user = [NSString stringWithFormat:@"%@", [[NSUserDefaults standardUserDefaults]stringForKey:@"CustomerID"]]; 

//user = [[NSUserDefaults standardUserDefaults] stringForKey:@"CustomerID"]; 

NSString *LoginURLString = [NSString stringWithFormat:@"http://dispatch.americantaxi.com:8080/AT/servlet/OnlineOrderServices?command=retrieveCustomerCommonPlaces&customerId=%@", user]; 
//NSLog output: http://dispatch.americantaxi.com:8080/AT/servlet/OnlineOrderServices?command=retrieveCustomerCommonPlaces&customerId=2314084  

は、私の要求初期化子の残りの部分である:

NSString *urlString = LoginURLString; 
responseData = [NSMutableData data]; 
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]; 
[[NSURLConnection alloc] initWithRequest:request delegate:self]; 

とリクエストを処理する他の方法:

-(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ 
    [responseData setLength:0]; 
} 

-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ 
    [responseData appendData:data]; 
} 

-(void) connectionDidFinishLoading:(NSURLConnection *)connection{ 
    // [connection release]; 

    CommonPickUpArray = [[NSMutableArray alloc] init]; 
    CommonLocationInfoArray = [[NSMutableArray alloc] init]; 

    NSString *data = [[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding]; 
    NSLog(@"%@", data); 
} 

このリクエストは決して開始しません。なぜ私は本当に理解していない。私は2つの文字列をNSLogに出力しようとしましたが、いずれの場合もまったく同じように見えます。誰でも説明できますか?ご協力いただきありがとうございます!

編集:接続didFailWithError方法はこれを出力している。

Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0xf6a6f50 {NSUnderlyingError=0xf6a75d0 "bad URL", NSLocalizedDescription=bad URL}

出力の答え1:

2012-05-08 13:45:24.959 AmericanTaxi [1295:707]接続はエラーで失敗しました:悪いURL 2012-05-08 13:45:24.960 AmericanTaxi [1295:707] URLの:(ヌル)urlStringの

出力とLoginURLString:

2012-05-08 13:57:40.415 AmericanTaxi [1320:707] LoginURLString:http://dispatch.americantaxi.com:8080/AT/servlet/OnlineOrderServices?command=retrieveCustomerCommonPlaces&customerId=2314084

2012-05-08 13:57:40.417 AmericanTaxi [1320:707] urlstring:あなたdidFailWithErrorでhttp://dispatch.americantaxi.com:8080/AT/servlet/OnlineOrderServices?command=retrieveCustomerCommonPlaces&customerId=2314084

+0

どのようなタイプのcustomerIdですか? (整数または文字列) – samir

+0

NSLog(@ "%@"、LoginURLString) 'を実行するとどうなりますか? CustomerIDが本当にユーザーの設定に含まれていると確信していますか? –

+0

その初期のオブジェクトは、NSLog出力です(それがUserDefaultsに追加されたとき) –

答えて

1

、URLをチェックし、それはあなたのdidFailWithErrorデリゲートにこれを追加することによって、悪い理由を参照してください。

NSLog(@"Connection failed with error: %@", [error localizedDescription]); 
NSLog(@"for the URL: %@", [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]); 

ポスト結果。

+0

私は質問の一番下に投稿しました、アドレスはnullです...奇妙なのはなぜでしょうか? –

+0

さて、それは良いことではありません。あなたの問題があります。私の推測では、LoginURLStringはurlStringに代入する前にスコープを外れていますか?リクエストを作成する前にurlStringをログに記録し、urlStringに割り当てる前にLoginURLStringをログに記録します。ところで、なぜurlString変数を作成するのを邪魔しますか?リクエストを作成するときにLoginURLStringを使用することができます。 – Joel

+0

もし私がそれを行うと、両方の文字列がOKになります。私は –

関連する問題