Query about sendSynchronousRequset

Discussion in 'iOS Programming' started by shweta13, Sep 15, 2008.

  1. shweta13 macrumors member

    Joined:
    Aug 7, 2008
    #1
    Hi,

    I want to send a HTTP synchronous request.
    I tried using sendSynchronousRequset of NSURLConnection but I am facing exceptions and leaks.

    Can anyone please suggest me any way to send synchronous request??

    Thanks,
    Shweta
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Post the code you are using, the exact exceptions and details of the leaks.
     
  3. shweta13 thread starter macrumors member

    Joined:
    Aug 7, 2008
    #3


    NSError** pError;
    NSData* m_pRecData;
    NSURL *pUrl = [NSURL URLWithString:mad:"http://www.apple.com"];
    NSURLRequest* pRequest = [NSURLRequest requestWithURL:pUrl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
    NSURLResponse* pResponse = [[NSURLResponse alloc] initWithURL:pUrl MIMEType:mad:"RFC 2822" expectedContentLength:100 textEncodingName:mad:"name"];
    m_pRecData = [[NSURLConnection alloc] sendSynchronousRequest:pRequest returningResponse:&pResponse error:pError];







    *** -[NSURLConnection sendSynchronousRequest:returningResponse:error:]: unrecognized selector sent to instance 0x407cc0
    (gdb) continue
    2008-09-15 16:09:55.413 myhttp[929:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURLConnection sendSynchronousRequest:returningResponse:error:]: unrecognized selector sent to instance
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    Please use the code BB tags as that's unreadable...

    Edit: like this:

    Edit again your list like makes no sense whatsoever. You have allocated an instance of NSURLConnection but not initalised it. This will cause massive failures. You then send a class method to this instance. This will not work (which is why you get the unrecognized selector error). I think you need to look at the basic Cocoa documentation and understand the difference between a class and an instance method.

    Your last like should read

    Code:
    m_pRecData = [NSURLConnection sendSynchronousRequest:pRequest returningResponse:&pResponse error:pError];
    
     
  5. shweta13 thread starter macrumors member

    Joined:
    Aug 7, 2008
    #5


    Thanks a lot ...that was of great help...I now know where I went wrong..
     

Share This Page