Możesz przekazać informacje w nagłówku za pomocą klasy NSMutableURLRequest, a następnie wywołać klasę NSURLConnection (będzie ona wywoływać delegata połączenia).
patrz poniższy kod,
NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:[myServerUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:60.0];
//do post request for parameter passing
[theRequest setHTTPMethod:@"POST"];
//set the content type to JSON
[theRequest setValue:@"xml" forHTTPHeaderField:@"Content-Type"];
//passing key as a http header request
[theRequest addValue:@"value1" forHTTPHeaderField:@"key1"];
//passing key as a http header request
[theRequest addValue:@"value2" forHTTPHeaderField:@"key2"];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if(theConnection)
{
webData = [[NSMutableData data] retain];
}
else
{
NSLog(@"theConnection is NULL");
}
[theConnection release];
Dodawanie custum klucz-wartość w NSMutableURLRequest nie działa dla HTTPS ... Każdy pomysł ?? – DShah
Adresy URL to HTTP lub HTTPS, nie ma znaczenia. NSMutableRequest wysyła atrybut w obu przypadkach. Czy zajmujesz się delegowaniem uwierzytelniania dla usługi HTTPS? –
Twierdzisz, że ustawiasz typ zawartości na JSON, a mimo to ustawiasz go na xml? Musisz ustawić go na 'application/json' – Houman