これはかなり混乱しています。私は、次に入れた場合: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
どのようなタイプのcustomerIdですか? (整数または文字列) – samir
NSLog(@ "%@"、LoginURLString) 'を実行するとどうなりますか? CustomerIDが本当にユーザーの設定に含まれていると確信していますか? –
その初期のオブジェクトは、NSLog出力です(それがUserDefaultsに追加されたとき) –