Note that there are some explanatory texts on larger screens.

plurals
  1. POError with headers of NSMutableRequest
    text
    copied!<p>i had a problem with a NSMutableURLRequest, i want to translate this</p> <pre><code>curl -b $cookie -F "data=foo" -F "user=bar" http://some/stuff.cgi -H 'X-Requested-With: XMLHttpRequest </code></pre> <p>my code is</p> <pre><code> NSString *params = [NSString stringWithFormat:@"data=%@&amp;user=bar", aUrl]; NSURL *url = [NSURL URLWithString:[[NSString alloc] initWithFormat:[NSString stringWithFormat:@"http://%@:%d/stuff.cgi", _host, _port]]]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:5.0]; [request setHTTPMethod:@"POST"]; [request setHTTPBody:[params dataUsingEncoding:NSUTF8StringEncoding ]]; [request setValue:[NSString stringWithFormat:@"http://%@/stuff.php", _host] forHTTPHeaderField:@"Referer"]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [request setValue:@"XMLHttpRequest" forHTTPHeaderField:@"X-Requested-With"]; NSArray *availableCookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@", _host]]]; NSDictionary *headers = [NSHTTPCookie requestHeaderFieldsWithCookies:availableCookies]; [request setAllHTTPHeaderFields:headers]; NSLog(@"headers: %@", [request allHTTPHeaderFields]); NSURLResponse *response; NSError *error; NSData *urlData = [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;response error:&amp;error]; ... </code></pre> <p>but it don't work, i'm make search without results and i' don't know where is the problem.</p> <p>Thanks.</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