What's the equivalent of this curl request in Objective-C? -
i have following curl command:
curl -x post \ -h "x-dadadadad: apitokenint" \ -f "log=@logfile.log" \ apilink.com i'd perform similar action in objective-c code, don't know how. equivalent of above in objective-c?
// create request. nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:[nsurl urlwithstring:@"https://rink.hockeyapp.net/api/2/apps/appid/crashes/upload"]]; // specify post request request.httpmethod = @"post"; // how set header fields [request setvalue:@"apitokenint" forhttpheaderfield:@"x-hockeyapptoken"]; // convert data , set request's httpbody property nsstring *stringdata = @"some data"; nsdata *requestbodydata = [stringdata datausingencoding:nsutf8stringencoding]; request.httpbody = requestbodydata; // create url connection , fire request nsurlconnection *conn = [[nsurlconnection alloc] initwithrequest:request delegate:self]; the parameters mention can set in url or in body of post request.
update - forms
if want send post request , set type form, set header of request so:
[request setvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"content-type"]; update 2 - multiple headers
in case going need set multiple headers, can done. can using addvalue method instead of setvalue method so:
[request addvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"content-type"]; [request addvalue:@"apitokenint" forhttpheaderfield:@"x-hockeyapptoken"];
Comments
Post a Comment