NSURLRequest setting the HTTP header

后端 未结 6 2055
名媛妹妹
名媛妹妹 2020-12-12 12:21

I need to set the HTTP header for a request. In the documentation for the NSURLRequest class I didn\'t find anything regarding the HTTP header. How can I set the HTTP header

6条回答
  •  -上瘾入骨i
    2020-12-12 13:12

     NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60];
    
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setValue:@"your value" forHTTPHeaderField:@"for key"];//change this according to your need.
    [request setHTTPBody:postData];
    

提交回复
热议问题