1

Hello friends i am using https server data using JSOn webservice but i don't know what the problem of certificate. i had already work with http data but am not work with secure https data.. can any one help me???

Hiren
  • 12,720
  • 7
  • 52
  • 72
  • Can you access the service using HTTPS from a desktop browser? Does it show any security warnings? – Thilo Mar 22 '11 at 11:09

2 Answers2

3

I'd recommend the ASIHTTPRequest library for dealing with HTTP requests in iOS apps. I use it for all of our apps.

Are you using a self-signed certificate? If so, you'll need to set the 'validatesSecureCertificate' to NO or the request will fail.

Here's some code for doing a post on HTTPS

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:@"https://example.com/post"];
[request setPostValue:email forKey:@"email"];
[request setPostValue:name forKey:@"name"];

// IMPORTANT: allows our self-signed cert to be ok
request.validatesSecureCertificate = NO;

[request startSyncronous];

 NSLog(@"post returned a %d", [request responseStatusCode] );

 NSError *error = [request error];
 if (!error) {
   NSString *response = [request responseString];
   NSLog(@"SUCCESS! Response is %@", response);
 } else {
  NSLog(@"FAIL!! %@", [error description] );
 }     

If you'd rather use the built-in Apple stuff, then Erik Aigner's answer explains how to deal with this using NSURLConnection.

Before you start coding I'd recommend using a CURL command to test the connection from your dev machine e.g. for the example above:

 curl -i -L -k -X POST "https://example.com/test" -d "email=foo@example.com&name=bar"

If this doesn't work, then the code above won't work either.

Ben Clayton
  • 80,996
  • 26
  • 120
  • 129
  • thnx for your response. but i want to use get method not post method and m never work with https:// webservice data. can you give me any related example link.. – Hiren Mar 23 '11 at 05:54
1

If you just deal with fetching data from a HTTPS connection, just use the NSURLConnection. They also handle HTTPS traffic.

Have a look at this question for certificate handling: HTTPS with NSURLConnection

Community
  • 1
  • 1