Note that there are some explanatory texts on larger screens.

plurals
  1. PONSURLConnection GET and POST not working
    primarykey
    data
    text
    <p>I am not getting the correct output from the server. The response I get back everytime is:</p> <blockquote> <p>Gone</p> <pre><code>/prod/bwckgens.p_proc_term_datehas been permanently removed from this server. </code></pre> </blockquote> <p>This is usually recieved when you just direct the web browser to the page <a href="https://selfservice.mypurdue.purdue.edu/prod/bwckgens.p_proc_term_date" rel="nofollow">here</a> instead of going through <a href="https://selfservice.mypurdue.purdue.edu/prod/bwckschd.p_disp_dyn_sched?" rel="nofollow">this</a> page first. This makes me come to the conclusion that a cookie isn't being saved, but I read in the documentation that this is all handled by the NSURLConnection object. Is there something I am doing wrong here?</p> <pre><code>#import "PCFViewController.h" @interface PCFViewController () @end NSMutableData *mutData; @implementation PCFViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (IBAction)queryServer { NSURL *url = [NSURL URLWithString:@"https://selfservice.mypurdue.purdue.edu/prod/bwckschd.p_disp_dyn_sched"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLCacheStorageAllowed timeoutInterval:3.0]; //the reason I perform a GET here is just to get a cookie and communicate like a normal web browser, since directly doing a POST to the proper address isn't working [request setHTTPMethod:@"GET"]; [request setValue:@"text/html; charset=UTF-8" forHTTPHeaderField:@"Content-Type"]; NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; if (connection) { mutData = [NSMutableData data]; } } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { NSLog(@"Succeeded! Received %d bytes of data",[mutData length]); NSString *str = [[NSString alloc] initWithData:mutData encoding:NSUTF8StringEncoding]; //just to see the contents(for debugging) NSLog(@"%@", str); [self handleConnection:connection]; } -(void)handleConnection:(NSURLConnection *)connection { //this is the first step if ([@"/prod/bwckschd.p_disp_dyn_sched" isEqualToString:[[[connection originalRequest] URL] path]]) { //first request //POST NSURL *url = [NSURL URLWithString:@"https://selfservice.mypurdue.purdue.edu/prod/bwckgens.p_proc_term_date"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLCacheStorageAllowed timeoutInterval:3.0]; [request setHTTPMethod:@"POST"]; NSString *args = @"p_calling_proc=bwckschd.p_disp_dyn_sched&amp;p_term=201320"; NSData *requestBody = [args dataUsingEncoding:NSUTF8StringEncoding]; [request setHTTPBody:requestBody]; connection = [connection initWithRequest:request delegate:self]; [connection start]; if (connection) { mutData = [NSMutableData data]; } //second step. Here I send the list of classes(COMPUTER SCIENCE) I want to display as well as the term SPRING2013 }else if([@"/prod/bwckgens.p_proc_term_date" isEqualToString:[[[connection currentRequest] URL] path]]) { NSURL *url = [NSURL URLWithString:@"https://selfservice.mypurdue.purdue.edu/prod/bwckschd.p_get_crse_unsec"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLCacheStorageAllowed timeoutInterval:3.0]; [request setHTTPMethod:@"POST"]; NSString *args = @"term_in=201320&amp;sel_subj=dummy&amp;sel_day=dummy&amp;sel_schd=dummy&amp;sel_insm=dummy&amp;sel_camp=dummy&amp;sel_levl=dummy&amp;sel_sess=dummy&amp;sel_instr=dummy&amp;sel_ptrm=dummy&amp;sel_attr=dummy&amp;sel_subj=CS&amp;sel_crse=dummy&amp;sel_title=dummy&amp;sel_schd=%25&amp;sel_from_cred=&amp;sel_to_cred=&amp;sel_camp=%25&amp;sel_ptrm=%25&amp;sel_instr=%25&amp;sel_sess=%25&amp;sel_attr=%25&amp;begin_hh=0&amp;begin_mi=0&amp;begin_ap=a&amp;end_hh=0&amp;end_mi=0&amp;end_ap=a"; NSData *requestBody = [args dataUsingEncoding:NSUTF8StringEncoding]; [request setHTTPBody:requestBody]; connection = [connection initWithRequest:request delegate:self]; [connection start]; if (connection) { mutData = [NSMutableData data]; } //the courses should be shown now I have to parse the data }else if([@"/prod/bwckschd.p_get_crse_unsec" isEqualToString:[[[connection currentRequest] URL] path]]) { } } -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { NSLog(@"%@\n", error.description); } - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { [mutData setLength:0]; NSLog(@"%@\n", response.description); } -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { [mutData appendData:data]; } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload