我得到一個令牌數字表單登錄api響應,我需要發送這個令牌的url與http頭字段。請首先從我的登錄api中獲得我的回覆。如何在httpheader字段中傳遞令牌號碼?
{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6ImpvaG4uc21pdGhAZ21haWwuY29tIiwiaWQiOiI1NzFkYzI3NmU0YjA1NjVmNTcwZjM2ZGQiLCJpYXQiOjE0NjMwMzY2Nzd9.3p2lXjOvQ-iIJZWr4GwuHCYf9VCDZbb3l9O1a8d7Eqs","data":{"name":"John Smith","role":"driver"},"message":"success"}
現在我需要在另一個URL發送此托克和我在一個字符串保存它。請查看標題字段的代碼。
- (void)viewDidLoad {
[super viewDidLoad];
token = [[NSUserDefaults standardUserDefaults]objectForKey:@"Accesstoken"];
NSLog(@"Accesstoken %@", token);
NSURL *theURL = [NSURL URLWithString:@"http://qa.networc.in:1336/api/dispatcher/rideHistory/:page"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:theURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:20.0f];
//Specify method of request(Get or Post)
[theRequest setHTTPMethod:@"GET"];
//Pass some default parameter(like content-type etc.)
[theRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[theRequest setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
//Now pass your own parameter
[theRequest setValue:token forHTTPHeaderField:@"Authorization"];
NSLog(@"req %@", theRequest);
NSURLResponse *theResponse = NULL;
NSError *theError = NULL;
NSData *theResponseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&theResponse error:&theError];
//Now you can create a NSDictionary with NSJSONSerialization
NSDictionary *dataDictionaryResponse = [NSJSONSerialization JSONObjectWithData:theResponseData options:0 error:&theError];
NSLog(@"url to send request= %@",theURL);
NSLog(@"%@",dataDictionaryResponse);
}
什麼是您的令牌請求類型 –
令牌請求類型是GET –
是你的令牌值日誌 –