如何在Objective-C中使用HttpGet类?

我是iPhone开发新手,我从Google获取访问令牌后,我解码它,现在我只是想检查他/她是否是一个注册用户。我在Android的代码,我想转换它到Objective-C中。

class HttpHelper { private static String token = null; public static void setToken(String token) { HttpHelper.token = token; } public static String getUrlContentAsString(String url, boolean ignoreHeader) { try { HttpGet request =new HttpGet(url); DefaultHttpClient client = new DefaultHttpClient(); if (!ignoreHeader && HttpHelper.token != null) request.addHeader(new BasicHeader("Authorization",HttpHelper.token)); HttpResponse response = client.execute(request); HttpEntity responseEntity = response.getEntity(); BufferedReader reader = new BufferedReader(new InputStreamReader(responseEntity.getContent())); StringBuilder sb = new StringBuilder(); while (true) { String line = reader.readLine(); if (line != null) sb.append(line); else break; } reader.close(); return sb.toString(); } catch (Exception e) { Log.e( "VerboActivity", e.getMessage()); } return null; } 

谁能帮我? 提前致谢。

试试这段代码

  NSMutableURLRequest *request=[[NSMutableURLRequest alloc] init]; [request setHTTPMethod:@"GET"]; 

设置头文件use- [request setValue: headerValue forHTTPHeaderField: headerfieldType ];

要设置身体使用 – [请求setHTTPBody: body(NSData) ];

最后得到响应 –

 NSURLResponse *response; NSData *responseData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];