1

Here is my php code.

public function PostCaseJson() {

    $case = Input::get('keyword');

    switch($case)
    {

        default:
        {       
            $email = Input::get('email');
            $password = Input::get('password');
            $auth = $this->authenticationURL($email, $password);
            $return = array('sc'=>$auth.'xx'.$case,'dt'=>$password);
        }
    }
     return json_encode($return);
}

below is my Xcode code.

NSString *newUrl = [[NSString alloc] initWithFormat:@"http://xxxxxx.com/authentication/post"];
    NSString *post = [NSString stringWithFormat:@"keyword=login&email=gggg@xxx.com&password=112211521"];

NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc]init];
[request setURL:[NSURL URLWithString:newUrl]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"applcation/x-www-form-urlencoded;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
NSURLRequest *response;
NSData *POSTReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
NSString *theReply = [[NSString alloc] initWithBytes:[POSTReply bytes] length:[POSTReply length] encoding:NSASCIIStringEncoding];
NSLog(@"Reply: %@",theReply);

But at the end, i success reach the server, but the keyword, email and password seems like fail to reach the server. The results from server is just reach the url, but post nothing. i had try to return the keyword, email and password, it seems like don't have any value inside the parameter.

please help, thanks!

Lazarus
  • 427
  • 2
  • 8
  • 14
  • Use a network analyzer such as Charles Proxy (free trial) to see exactly what is sent to the server and what the server is returning. Also get a good book on Objective-C and the Foundation classes. – zaph Feb 04 '14 at 06:10
  • what u need from the server – Anbu.Karthik Feb 04 '14 at 06:12
  • i just want make sure i had success post those parameter like keyword, email and password to the server for process and return the results. – Lazarus Feb 04 '14 at 06:14
  • i using laravel framework. – Lazarus Feb 04 '14 at 06:16
  • i had use charles proxy to check. this is what i return. POST /authentication/post HTTP/1.1 Host: xxxxxx.com User-Agent: magstreet/1.0 CFNetwork/548.1.4 Darwin/11.4.2 Content-Length: 52 Accept: */* Content-Type: applcation/x-www-form-urlencoded;charset=UTF-8 Accept-Language: en-us Accept-Encoding: gzip, deflate Cookie: laravel_session=nqgcpb2ut36qgktcmvfsv29im7 Connection: keep-alive keyword=login&email=gggg@xxx.com&password=112211521 – Lazarus Feb 04 '14 at 07:12

0 Answers0