Ios 如何在iPhone编程中发送带有身份验证挑战的HTTP客户端请求
我正在尝试发送具有身份验证安全性的http请求。它将以JSON格式给出响应。我正在寻找任何用于发送http请求以获取响应的教程或示例代码。我已经搜索过,但没有得到任何有用的教程。请帮助我,提前感谢。您可以实现“NSURLConnectionDataDelegate”。在you.h文件中,执行以下操作Ios 如何在iPhone编程中发送带有身份验证挑战的HTTP客户端请求,ios,iphone,objective-c,http,nsurlconnection,Ios,Iphone,Objective C,Http,Nsurlconnection,我正在尝试发送具有身份验证安全性的http请求。它将以JSON格式给出响应。我正在寻找任何用于发送http请求以获取响应的教程或示例代码。我已经搜索过,但没有得到任何有用的教程。请帮助我,提前感谢。您可以实现“NSURLConnectionDataDelegate”。在you.h文件中,执行以下操作 @interface youClass : NSObject<NSURLConnectionDataDelegate> 希望这有帮助。:) 假设您希望从服务中获取数据,并且您有相应的U
@interface youClass : NSObject<NSURLConnectionDataDelegate>
希望这有帮助。:) 假设您希望从服务中获取数据,并且您有相应的URl,因此下面的方法将从给定URl内的服务器获取数据 -(NSString*)getDataFromService:(NSString*)strUrl{ } 因此,在响应字符串中,您有来自给定url的服务器的响应数据 为此,您需要从github加载名为ASIHTTPRequest的库,以下是链接
您需要在iOS上解析JSON的教程吗?我已经编辑了我的问题。也许可以在iOS上查看AFNetworkinggitHub@preetam据我所知,该库不再受支持。这就是为什么我建议建立网络
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace: (NSURLProtectionSpace *)protectionSpace {
// NSLog(@"canAuthenticateAgainstProtectionSpace:");
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge: (NSURLAuthenticationChallenge *)challenge {
// NSLog(@"didReceiveAuthenticationChallenge:");
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
// NSLog(@"connectionDidFinishLoading");
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
// NSLog(@"Recived data!!!");
}
NSURL *url = [NSURL URLWithString:strUrl];
NSString *response;
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request addBasicAuthenticationHeaderWithUsername:USERNAME
andPassword:PASSWORD];
[request startSynchronous];
NSError *error = [request error];
if (!error) {
response = [request responseString];
}
else
{
response=nil;
}
return response;