Note that there are some explanatory texts on larger screens.

plurals
  1. POTranslating C++ To Objective C
    text
    copied!<p>It's about some days now i'm struggling doing Archaeology work trying to translating a c++ code snippet using Qt to objective-c, it's for sending a request in order to parse xml coming from a server as a response. I really try but can't achieve it. If someone could give me some help.</p> <pre><code>void RestClient::_prepareRequest( QNetworkRequest&amp; a_request, const QString&amp; a_uri ) { QSslConfiguration config(QSslConfiguration::defaultConfiguration()); config.setProtocol(QSsl::SslV3); config.setSslOption(QSsl::SslOptionDisableServerNameIndication, true); a_request.setSslConfiguration(config); a_request.setRawHeader("Accept", "application/xml"); a_request.setRawHeader("Content-Type", "application/x-www-form-urlencoded"); QByteArray l_api_key; l_api_key.append( toQString( m_api_key) ); QByteArray l_request_hash; l_request_hash.append( toQString( _buildRequestHash( toStlString(a_uri) ) ) ); a_request.setRawHeader("EMApikey", l_api_key ); a_request.setRawHeader("EMRequestHash", l_request_hash ); a_request.setUrl( QUrl( a_uri ) ); } - (NSString *)hmacsha1:(NSString *)data secret:(NSString *)key { const char *cKey = [key cStringUsingEncoding:NSASCIIStringEncoding]; const char *cData = [data cStringUsingEncoding:NSASCIIStringEncoding]; unsigned char cHMAC[CC_SHA1_DIGEST_LENGTH]; CCHmac(kCCHmacAlgSHA1, cKey, strlen(cKey), cData, strlen(cData), cHMAC); NSData *HMAC = [[NSData alloc] initWithBytes:cHMAC length:sizeof(cHMAC)]; NSString *hash = [HMAC base64EncodedStringWithOptions:(nil)]; return hash; </code></pre> <p>}</p> <p>and here is my code :</p> <pre><code>- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; if ([stories count] == 0) { NSString * myServerUrl = @"**************"; NSString * l_api_key = @"*******************************"; NSString * l_secret_key = @"************************************"; NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:[myServerUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0]; //do post request for parameter passing [theRequest setHTTPMethod:@"GET"]; [theRequest setValue:@"xml" forHTTPHeaderField:@"xml"]; [theRequest addValue:@"l_api_key" forHTTPHeaderField: l_api_key]; [theRequest addValue:@"l_request_hash" forHTTPHeaderField:[self hmacsha1:l_api_key secret:l_secret_key]]; NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; if( theConnection ) { NSLog(@"we get here !"); NSURL *webData = [[NSMutableData data] retain]; [self parseXMLFileAtURL: webData]; cellSize = CGSizeMake([newsTable bounds].size.width, 60); } else { NSLog(@"theConnection is NULL"); } [theConnection release]; } //cellSize = CGSizeMake([newsTable bounds].size.width, 60); </code></pre> <p>}</p>
 

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