Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>In Your case</strong></p> <pre><code> NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"http://my example.com/Accountservice/Security/ValidateAccess?accesscode=abcd&amp;type=1"]]; </code></pre> <p>You can not pass <strong>parameter</strong> with <code>URL in POST</code> method such like ,<br> <code>....?accesscode=abcd&amp;type=1"</code></p> <p>You can use the following code snippet, as described <a href="http://panditpakhurde.wordpress.com/2009/04/16/posting-data-to-url-in-objective-c/">in this article</a>:</p> <p>Here, I simple describe how can use of POST method. </p> <blockquote> <p><strong>1.</strong> Set post string with actual username and password.</p> <pre><code>NSString *post = [NSString stringWithFormat:@"&amp;Username=%@&amp;Password=%@",@"username",@"password"]; </code></pre> <p><strong>2.</strong> Encode the post string using <code>NSASCIIStringEncoding</code> and also the post string you need to send in NSData format.</p> <pre><code>NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; </code></pre> <p>You need to send the actual length of your data. Calculate the length of the post string.</p> <pre><code>NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]]; </code></pre> <p><strong>3.</strong> Create a Urlrequest with all the properties like <code>HTTP</code> method, http header field with length of the post string. Create <code>URLRequest</code> object and initialize it.</p> <pre><code>NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; </code></pre> <p>Set the Url for which your going to send the data to that request.</p> <pre><code>[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.abcde.com/xyz/login.aspx"]]]; </code></pre> <p>Now, set <strong>HTTP</strong> method (<em>POST or GET</em>). Write this lines as it is in your code.</p> <pre><code>[request setHTTPMethod:@"POST"]; </code></pre> <p>Set <code>HTTP</code> header field with length of the post data.</p> <pre><code>[request setValue:postLength forHTTPHeaderField:@"Content-Length"]; </code></pre> <p>Also set the Encoded value for HTTP header Field.</p> <pre><code>[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"]; </code></pre> <p>Set the <code>HTTPBody</code> of the urlrequest with postData.</p> <pre><code>[request setHTTPBody:postData]; </code></pre> <p><strong>4.</strong> Now, create URLConnection object. Initialize it with the URLRequest.</p> <pre><code>NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self]; </code></pre> <p>It returns the initialized url connection and begins to load the data for the url request. You can check that whether you <code>URL</code> connection is done properly or not using just <strong>if/else</strong> statement as below.</p> <pre><code>if(conn) { NSLog(@”Connection Successful”) } else { NSLog(@”Connection could not be made”); } </code></pre> <p><strong>5.</strong> To receive the data from the HTTP request , you can use the delegate methods provided by the URLConnection Class Reference. Delegate methods are as below.</p> <pre><code>- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData*)data </code></pre> <p>Above method is used to receive the data which we get using post method.</p> <pre><code>- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error </code></pre> <p>This method , you can use to receive the error report in case of connection is not made to server.</p> <pre><code>- (void)connectionDidFinishLoading:(NSURLConnection *)connection </code></pre> <p>The above method is used to process the data after connection has made successfully.</p> </blockquote> <p><strong>Also Refer</strong> <a href="http://deusty.blogspot.in/2006/11/sending-http-get-and-post-from-cocoa.html">This</a> <strong>and</strong> <a href="http://yuvarajmanickam.wordpress.com/2012/10/17/nsurlconnection-basics-for-ios-beginners/">This</a> <strong>documentation</strong> for <code>POST</code> method. </p> <p>And here is best example with source code of <a href="http://kemal.co/index.php/2012/02/fetching-data-with-getpost-methods-by-using-nsurlconnection/">HTTPPost Method.</a></p>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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